假设foo
类没有重载的赋值运算符。当为两个 foo
对象赋值 a = b;
时会发生什么?
选项有:
- 使用自动赋值运算符
- 复制构造函数
最佳答案
这取决于:
A a;
//this is not an assignment, it is equivalent to A b(a);
A b = a; //default copy constructor is called
A c;
//assignment
c = a; //default assignment operator is called
关于c++ - 如果未定义赋值运算符,是否会调用复制构造函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8804823/