由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - copy constructor问题。
相关主题
C++编程原则的问题C++的"初始化"小结
C++ vectorC++ Pitfalls , you may not know [转载]
包含指针的类和vector的问题*(&b1)=b编译不过,b1=b可以,区别是?
请问C++如何初始化类时就传入一个数组参数C++ 里push_back 一问
请问static variable init的问题?C++ auto type是怎么推算的?
[合集] 关于C++ Class Template编程一问const reference in copy constructor
[合集] C++的弱问题[c++] reference 真得不能bound to a second object 么?
刚看完类这一章,有些大小问题,请指教,谢谢C++问题,confusing...
相关话题的讨论汇总
话题: copy话题: class话题: object话题: member
进入Programming版参与讨论
1 (共1页)
j****g
发帖数: 597
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里好像啥都不用做,只用赋值就行了吧?
t****t
发帖数: 6806
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里好像啥都不用做,只用赋值就行了吧?

j****g
发帖数: 597
3
That's the question. :)
牛牛就是牛牛啊。。。
d*******d
发帖数: 2050
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里好像啥都不用做,只用赋值就行了吧?

o*o
发帖数: 404
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里好像啥都不用做,只用赋值就行了吧?

j****g
发帖数: 597
6
For 3 and 4, what will happen then?
z***e
发帖数: 5393
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?
c********x
发帖数: 84
8
whenever you have a class member, you need deep copy.
1 (共1页)
进入Programming版参与讨论
相关主题
C++问题,confusing...请问static variable init的问题?
C++ questions[合集] 关于C++ Class Template编程一问
[合集] 关于C++ default copy constructor[合集] C++的弱问题
[合集] C++问题(copy constructor)刚看完类这一章,有些大小问题,请指教,谢谢
C++编程原则的问题C++的"初始化"小结
C++ vectorC++ Pitfalls , you may not know [转载]
包含指针的类和vector的问题*(&b1)=b编译不过,b1=b可以,区别是?
请问C++如何初始化类时就传入一个数组参数C++ 里push_back 一问
相关话题的讨论汇总
话题: copy话题: class话题: object话题: member