E
eastern_strider
Hi,
In the following code snippet, if I comment out line b, the output
becomes:
constructor
constructor
whereas if I comment out line c, the output becomes:
constructor
copy constructor
Any explanations regarding what is causing this difference is
appreciated.
#include <iostream>
using namespace std;
class A {
public:
A() { cout << "constructor" << endl; }
A(const A& obj) { cout << "copy constructor" << endl; }
A foo() { return A(); }
};
int main()
{
A a;
A b(a); // <--- line b
A c(a.foo()); // <--- line c
return 0;
}
In the following code snippet, if I comment out line b, the output
becomes:
constructor
constructor
whereas if I comment out line c, the output becomes:
constructor
copy constructor
Any explanations regarding what is causing this difference is
appreciated.
#include <iostream>
using namespace std;
class A {
public:
A() { cout << "constructor" << endl; }
A(const A& obj) { cout << "copy constructor" << endl; }
A foo() { return A(); }
};
int main()
{
A a;
A b(a); // <--- line b
A c(a.foo()); // <--- line c
return 0;
}