avatar
copy constructor问题。# Programming - 葵花宝典
j*g
1
How would a copy constructor behave if the class had an Object as a member
Variable?
在C++里面你必须call member object的copy constructor, 或使用初始化。如果
override了operator=也可以用=进行赋值。
Is it a complete answer? Or anything else need to say?
在Java里好像啥都不用做,只用赋值就行了吧?
avatar
t*t
2
you "call member object's copy constructor" BY using "初始化". there's no
2nd way to call member object's copy constructor (in the class' copy
constructor).
actually i think you meant to ask, how would a *default* copy constructor
behave, if blahblah

【在 j****g 的大作中提到】
: How would a copy constructor behave if the class had an Object as a member
: Variable?
: 在C++里面你必须call member object的copy constructor, 或使用初始化。如果
: override了operator=也可以用=进行赋值。
: Is it a complete answer? Or anything else need to say?
: 在Java里好像啥都不用做,只用赋值就行了吧?

avatar
j*g
3
That's the question. :)
牛牛就是牛牛啊。。。
avatar
d*d
4
the member object will be initialized by its own copy constructor.
if you don't provide its copy constructor, the compiler will make one for yo
u, which will be bit copy.

【在 j****g 的大作中提到】
: How would a copy constructor behave if the class had an Object as a member
: Variable?
: 在C++里面你必须call member object的copy constructor, 或使用初始化。如果
: override了operator=也可以用=进行赋值。
: Is it a complete answer? Or anything else need to say?
: 在Java里好像啥都不用做,只用赋值就行了吧?

avatar
o*o
5
A default copy constructor does not do a Bitwise Copy under the following
circumstances
* When the class contains a member object of a class for which a copy
assignment operator exists
* When the class is derived from a base class for which a copy
assignment operator exists
* When the class declares one or more virtual functions (we must not
copy the vptr address of the right-hand class object, since it might be a
derived class object)
* When the class inherits from a virtual bas

【在 j****g 的大作中提到】
: How would a copy constructor behave if the class had an Object as a member
: Variable?
: 在C++里面你必须call member object的copy constructor, 或使用初始化。如果
: override了operator=也可以用=进行赋值。
: Is it a complete answer? Or anything else need to say?
: 在Java里好像啥都不用做,只用赋值就行了吧?

avatar
j*g
6
For 3 and 4, what will happen then?
avatar
z*e
7
For all the 4 conditions, it just means the copy constructor of the base
class is going to be invoked.

【在 j****g 的大作中提到】
: For 3 and 4, what will happen then?
avatar
c*x
8
whenever you have a class member, you need deep copy.
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。