I will first comment on the third:
Foo obj3=Foo(args);
It does not use operator= , which is called copying. Instead, it calls the constructor instance (theoretically). There are no assignments. Thus, theoretically, there are two objects, one of which is temporary, and the other is obj3 . The compiler can optimize the code by fully returning the creation of a temporary object.
Now second:
Foo obj2;
Here, the first line creates an object that calls the default constructor. Then it calls operator= passing the temporary object created from the Foo(args) expression. Thus, there are only two objects: operator= takes an argument using a const reference (which should do).
And as for the first, you're right.
Nawaz source share