您好我有以下代码:
#include <iostream>
using namespace std;
class A {
public:
int p;
A() {
cout << "Inside A constr" << endl;
}
A(const A& a) {
cout << "Inside copy constr" << endl;
}
A* operator=(const A& b) {
cout << "Inside assignment oper" << endl;
}
};
A f1() {
cout << "Inside f1" << endl;
A a;
cout << "Just before return from f1" << endl;
return a;
}
int main() {
A x = f1();
return 0;
}
当我执行上述程序时,我得到以下输出
Inside f1
Inside A constr
Just before return from f1
我怀疑为什么在执行语句时没有调用复制构造函数 A x = f1();