哪些成员是自动创建的,哪些成员不会被继承? [英] Which members are created automatically, which members are not inherited?

查看:61
本文介绍了哪些成员是自动创建的,哪些成员不会被继承?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很长一段时间,我对这个问题感到不安。我想如果我终于得到了你的帮助,我会接近一个优秀的C ++

程序员。我只能依靠你的专业知识和帮助。我读过一些书,但是没有书专注于此。难道你不认为这是C ++编程语言的重要内容吗?所以你的知识对他人来说是非常有益的,特别是我。

1.会自动创建哪个(多少个)成员?


Scott Meyers似乎在他的早期版本中给出了这个列表

<< Effective C ++,2nd>>,但他删除了1(或2,也许你知道) ,

包含6个成员的列表是:


默认构造函数,复制构造函数,析构函数,赋值

运算符,a一对地址的操作符(即const,非常量)。


但是在后来的版本中(不是新版本,我不读第三篇)他

从该列表中删除了最后一对运算符而没有详细信息

描述,或者他在没有

之前将该对放在该列表中原因。这是我的抱怨。


Bjarne Stroustrup博士提到操作员,(即逗号)也是一个

预定义成员(他提到总计3:=,& ;和,在TC ++ PL sec

11.2.2),但Andrew Koenig说这不是一个成员函数。在我之前的

帖子中。显然,它是在一个类体内,所以我不会理解他说的话。


Herb Sutter提及&&,||并且,(逗号)在他的新书C ++编码

标准。但他没有提供自动创建的完整列表

班级成员。他总是谈论使用

矢量,列表或类似的东西与大师的一些神奇的东西。这是我的抱怨。


如何新增和删除,以及其他一些函数或运算符

我不知道这个名字。谁会给出完整的清单?

2.哪些(多少)成员不能继承?


我知道默认ctor,复制ctor,dctor,赋值运算符不能继承
。前三个成员分别使用相同的名称

即使基类名称和派生类名称也不同 - 它

很明显,但它有助于我理解原因非继承。

我可以理解操作员的分配也不会继承。


但我不确定是否还有其他成员也不能继承。


怎么样新的和删除,以及其他一些函数或运算符

我不知道这个名字。谁会给出完整的清单?

此致,


lovecreatesbeauty

解决方案

lovecreatesbeauty写道:

很长一段时间我对这个问题感到不安。我想如果我终于得到了你的帮助,我会接近一位优秀的C ++程序员。我只能依靠你的专业知识和帮助。我读过一些书,但没有书专注于此。你不觉得它是C ++编程语言的一个非常重要的东西吗?所以你的知识对其他人,特别是我有很大好处。

1.会自动创建哪些(多少)成员?

Scott Meyers似乎在他的
<<<<<<<<<<<<<<<<<<<<<<<<<>>>>> b为什么你不知道?你附近的图书馆有没有这两本书吗?

包含6个成员的列表是:

默认构造函数,复制构造函数,析构函数,赋值运算符
,一对地址的操作符(即const,非const)。

但是在后来的版本中(不是新版本,我不读第3版)他
从该列表中移除最后一对操作符而没有详细描述,或者在没有完全确信原因的情况下将该对放在该列表中。这是我的抱怨。


您应该联系Scott,然后。如果是抱怨,我的意思是。你知道吗,

Scott可以在互联网上找到...

Bjarne Stroustrup博士提到操作员,(即逗号)也是一个预定义的成员(他提到过)总计3:=,&和TC ++ PL sec 11.2.2),但Andrew Koenig说那不是一个成员函数。在我的
帖子之前。显然,它是一个集体内部,所以我不明白他说的话。


_who_说什么? Koenig或Stroustrup?

Herb Sutter提及&&,||并且,(逗号)在他的新书C ++编码标准中。但他也没有提供自动创建的班级成员的完整列表。他总是谈论使用
矢量,列表或与大师类似的东西的一些神奇的东西。这是我的抱怨。

新的和删除,以及其他一些我不知道名字的功能或操作员怎么样。谁会给出完整的清单?


完整清单是有条件的。例如,如果您有任何参数化的c-tor

,则不会生成默认的c-tor。分配op

如果有成员不允许,则不生成...

2.哪些(多少)成员不能继承?即使基类名称和派生类名称不同 - 它很明显,但它有助于我理解非继承的原因。我可以理解运算符赋值也不会被继承。


没有继承构造函数。永远。


析构函数的虚拟性是一种继承的特性。


_copy_赋值操作不是继承的。参数化可以是。

但是我不确定是否有其他成员也不能继承。

如何新增和删除,以及其他一些功能或操作符<我不知道这个名字。谁会给出一个完整的清单?




我认为没有一个完整而硬的清单。这都是相对的。


V


lovecreatesbeauty sade:

我是长期以来对这个问题感到不安。我想如果我终于得到了你的帮助,我会接近一位优秀的C ++程序员。我只能依靠你的专业知识和帮助。我读过一些书,但没有书专注于此。你不觉得它是C ++编程语言的一个非常重要的东西吗?所以你的知识对其他人,特别是我有很大好处。




< snipped Scott Meyers>

< snipped Bjarne Stroustrup>

< snipped Andrew Koenig>

< snipped Herb Sutter>


为什么不输入下一个级别并购买标准的副本?

ISBN:0470846747

那样你就不需要翻阅几本书了

找到有关语言功能的隐藏提示/答案,只需一个。


-

TB @ SWEDEN

I''m disturbed on this question on a long time. I think if I finally get
understand it with your kind help, I will get close to a excellent C++
programmer. And I only can rely on your expertise and help. I''ve read
some books, but no book focuses on this. Don''t you think it is a very
important thing of C++ programming language? So your knowledge is of
great benefit to others, especially me.
1. Which (How many) members will be created automatically?

Scott Meyers seems to give this list in a early print of his
<<effective C++, 2nd>>, but he removed 1 (or 2, perhaps you know it),
the list containing 6 members he gives is:

default constructor, copy constructor, destructor, assignment
operator, a pair of address-of operators (i.e. const, non-const) .

But in a later print (not a new edition, I don''t read the 3rd one) he
removed the last pair of operators from that list without a detail
description, or he put that pair in that list before without a
thoroughly convinced reason. That is my complaint.

Dr. Bjarne Stroustrup mentioned operator , (i.e. comma) is also a
predefined member (he mentioned total 3: =, &, and , in TC++PL sec
11.2.2), but Andrew Koenig said "That is not a member function." in my
post before. Obviously, it is inside a class body, so I do not
understand what he said.

Herb Sutter mentioned &&, || and , (comma) in his new book C++ coding
standard. But he did not give a complete list of automatically created
class members also. He always talks about some magic things on usage of
vector, list or some similar things with gurus. That is my complaint.

How about new and delete, and some others functions or operators which
I do not know the name. Who will give a complete list?
2. Which (How many) members can not be inherited?

I know default ctor, copy ctor, dctor, assignment operator can not be
inherited. The first three members share the same name respectively
even the base class name and the derived class name are different - it
is obvious, but it helps me to understand the reason of non-inherited.
I can understand operator assignment will not be inherited also.

But I am not sure if there are other members also can not be inherited.

How about new and delete, and some others functions or operators which
I do not know the name. Who will give a complete list?
Sincerely,

lovecreatesbeauty

解决方案

lovecreatesbeauty wrote:

I''m disturbed on this question on a long time. I think if I finally get
understand it with your kind help, I will get close to a excellent C++
programmer. And I only can rely on your expertise and help. I''ve read
some books, but no book focuses on this. Don''t you think it is a very
important thing of C++ programming language? So your knowledge is of
great benefit to others, especially me.
1. Which (How many) members will be created automatically?

Scott Meyers seems to give this list in a early print of his
<<effective C++, 2nd>>, but he removed 1 (or 2, perhaps you know it),
Why don''t you "know it"? Doesn''t your nearby library have both books?
the list containing 6 members he gives is:

default constructor, copy constructor, destructor, assignment
operator, a pair of address-of operators (i.e. const, non-const) .

But in a later print (not a new edition, I don''t read the 3rd one) he
removed the last pair of operators from that list without a detail
description, or he put that pair in that list before without a
thoroughly convinced reason. That is my complaint.
You should contact Scott, then. If it''s a complaint, I mean. You know,
Scott is available on Internet...
Dr. Bjarne Stroustrup mentioned operator , (i.e. comma) is also a
predefined member (he mentioned total 3: =, &, and , in TC++PL sec
11.2.2), but Andrew Koenig said "That is not a member function." in my
post before. Obviously, it is inside a class body, so I do not
understand what he said.
What _who_ said? Koenig or Stroustrup?
Herb Sutter mentioned &&, || and , (comma) in his new book C++ coding
standard. But he did not give a complete list of automatically created
class members also. He always talks about some magic things on usage of
vector, list or some similar things with gurus. That is my complaint.

How about new and delete, and some others functions or operators which
I do not know the name. Who will give a complete list?
The complete list is conditional. For example, if you have any
parameterised c-tor, the default c-tor is not generated. Assignment op
is not generated if there are members that don''t allow that...
2. Which (How many) members can not be inherited?

I know default ctor, copy ctor, dctor, assignment operator can not be
inherited. The first three members share the same name respectively
even the base class name and the derived class name are different - it
is obvious, but it helps me to understand the reason of non-inherited.
I can understand operator assignment will not be inherited also.
No constructors are inherited. Ever.

Virtualness of the destructor is an inherited trait.

The _copy_ assignment op is not inherited. Parameterized can be.
But I am not sure if there are other members also can not be inherited.

How about new and delete, and some others functions or operators which
I do not know the name. Who will give a complete list?



I don''t think there is a complete and hard-set list. It''s all relative.

V


lovecreatesbeauty sade:

I''m disturbed on this question on a long time. I think if I finally get
understand it with your kind help, I will get close to a excellent C++
programmer. And I only can rely on your expertise and help. I''ve read
some books, but no book focuses on this. Don''t you think it is a very
important thing of C++ programming language? So your knowledge is of
great benefit to others, especially me.



<snipped Scott Meyers>
<snipped Bjarne Stroustrup>
<snipped Andrew Koenig>
<snipped Herb Sutter>

Why not enter the next level and buy a copy of the standard?
ISBN: 0470846747
That way you won''t need to flip through several books to
find hidden hints/answers about language features, just one.

--
TB @ SWEDEN


这篇关于哪些成员是自动创建的,哪些成员不会被继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆