猜猜下面的代码结果是什么??
#include <iostream>
using namespace std;
class A
{
public:
A() {}
A(const A& a) { cout << "copy " << endl;}
A& operator=(const A&a) { cout << "== " << endl;
return *this;
}
};
int main()
{
A b;
A a = b;
return 0;
}
答案是copy 哈哈哈。
即使赋值运算符被重载了,这种情况也是用的拷贝构造函数