Hi,
Is there any difference between the 2 creation objects in the main() ?
I mean what does the compiler do with those 2 options, do they have the same assembly code ?
Another Q is - if i'm adding an explicit definition to the class like : CDefaultConstructor() { cout<<"Create"; } would it makes any difference ?
Is there any difference between the 2 creation objects in the main() ?
Yes, the two examples are different.
In the first example, the compiler allocates space for mX and provides a default constructor which does nothing.
In the second example, a temporary instance of CDefaultConstructor is pushed on the stack, its default constructor called (again provided by the compiler and does nothing). The temporay instance is then copied to ex_2_defConstructor using a compiler provided copy constructor.
do they have the same assembly code ?
No.
if i'm adding an explicit definition to the class like : CDefaultConstructor() { cout<<"Create"; } would it makes any difference ?
In what way?
In the first example, "Create" would be displayed once.
In the second example, "Create" would still only be displayed once, since ex_2_defConstructor would be constructed by the compiler provided copy constructor.
To make it more clear I would say that the copy constructor will not be used due to optimizaion. But it shall be declared and be accessible that the code could be compiled.
But at the same time in both examples the assembler code can be the same.