由以下代码混淆,至少应该调用两个构造函数,一个用于funcReturningA中的变量tmp,另一个用于main中的变量a。但输出只是一行:
带有args的构造函数
#include <iostream>
using namespace std;
class A {
private:
int member;
public:
A() {
cout << "Default constructor" << endl;;
}
A(int member) {
this->member = member;
cout << "constructor with args" << endl;
}
A(const A &a) {
cout << "copy constructor by ref" << endl;;
}
A &operator=(const A &a) {
cout << "copy assign operator by const ref" << endl;
}
A &operator=(A) {
cout << "copy assign operator by value" << endl;
}
};
A funcReturningA() {
A tmp(10);
return tmp;
}
int main(int argc, char **argv) {
........
A a = funcReturningA();
return 0;
}