c*r
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 了呢?这两个不是重复了吗?
: 那个高手解释解释, 多谢。
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
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.
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.
相关阅读
给推荐下 C++ stl 的经典书籍吧a c++ question.gcc的网页断了??在帮忙看看这个吧 C: int->char*thread model 和 效率如何写入版本信息有谁可以帮忙写个小小小软件[合集] 一个问题,谢谢指教 (转载)为什么这里大都是C++问题?贡献一c++面试题default linkage for const global variable in C/C++浮点数运算等于0的问题问问题C问个nontrivial Java问题python decorator 调用问题C#程序调用Windows C++ DLL的问题c中什么矩阵库可以做初始化转置相乘相加等基本运算?Ajax里面怎么设置cookieDoes <string> have a function called find_last_of()?这样的开源软件合作靠谱吗? (转载)