I'm learning ctors now and have a few question. At these lines:
Foo obj(args);
Foo obj2;
obj2 = Foo(args);
Foo obj3 = Foo(args);
First part: only 1 constructor called (Foo) and obj
is initialized. So, 1 object creation.
Second part: creating of temporary object obj2
, calling default ctor for it. Next lines we create another copy of Foo
and pass its copy into operator=()
. Is that right? So, 3 local temporary objects, 2 constructor callings.
Third part: create 1 object Foo
and pass its copy into operator=()
. So, 2 temprorary objects and 1 ctor calling.
Do I understand this right? And if it's true, will compiler (last gcc, for example) optimize these in common cases?