q*c 发帖数: 9453 | 1 我怎么觉得定义了 = 就不需要 copy ctor 了呢?这两个不是重复了吗?
那个高手解释解释, 多谢。 | c*r 发帖数: 278 | 2 They are different in nature. One is contructor, the other
is an operator.
Copy ctor initialize the object, while assignment operator
modifies the existing object.
ClassA X = Y; //need copy ctor for ClassA.
ClassA X;
X = Y; //need assignment operator.
【在 q*c 的大作中提到】 : 我怎么觉得定义了 = 就不需要 copy ctor 了呢?这两个不是重复了吗? : 那个高手解释解释, 多谢。
| q*c 发帖数: 9453 | 3 ft...thanks. make a lot sense.
I only consider class A = B case..
【在 c*r 的大作中提到】 : They are different in nature. One is contructor, the other : is an operator. : Copy ctor initialize the object, while assignment operator : modifies the existing object. : ClassA X = Y; //need copy ctor for ClassA. : ClassA X; : X = Y; //need assignment operator.
|
|