Confused by the following code, at least two constructors should have been called, one for variable tmp in funcReturningA and one for variable a in main. But the output is only a single line:
constructor with 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;
}