R
Robert Sturzenegger
class C
{
public:
C() { cout << "ctor" << endl; }
C(const C & rhs) { cout << "copy ctor" << endl; }
~C() { cout << "dtor" << endl; }
};
C c0; // A
C c1 = C(); // B
I could imagine, that line B causes the creation of a temporary object which
is used to intantiate c1 by means of the copy ctor. But it's not the case,
lines A and B cause the same (tested on several compilers). Is this
required? Or is the compiler free which way to do that? Is it optimization?
Thanks!
Robert Sturzenegger
{
public:
C() { cout << "ctor" << endl; }
C(const C & rhs) { cout << "copy ctor" << endl; }
~C() { cout << "dtor" << endl; }
};
C c0; // A
C c1 = C(); // B
I could imagine, that line B causes the creation of a temporary object which
is used to intantiate c1 by means of the copy ctor. But it's not the case,
lines A and B cause the same (tested on several compilers). Is this
required? Or is the compiler free which way to do that? Is it optimization?
Thanks!
Robert Sturzenegger