如果未定义赋值运算符,是否调用复制构造函数?

时间:2012-01-10 14:27:43

标签: c++

假设foo类没有重载的赋值运算符。为两个a = b;对象分配foo时会发生什么? 选项是:

  1. 使用自动赋值运算符
  2. 复制构造函数

1 个答案:

答案 0 :(得分:4)

取决于:

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