我有这个代码
#include <iostream>
using namespace std;
class Test{
public:
int a;
Test(int i=0):a(i){}
~Test(){
cout << a << endl;
}
Test(const Test &){
cout << "copy" << endl;
}
void operator=(const Test &){
cout << "=" << endl;
}
Test operator+(Test& p){
Test res(a+p.a);
return res;
}
};
int main (int argc, char const *argv[]){
Test t1(10), t2(20);
Test t3=t1+t2;
return 0;
}
输出:
30
20
10
为什么这里不调用复制构造函数?