1) As written, that's a function declaration; you need to change it slightly to get the behaviour you intend:
ABC a((ABC()));
or
ABC a = ABC();
In this case, the compiler has two choices:
- Create a temporary object using the default constructor, and initialise
a
from that using the copy constructor;
- Elide the copy, and directly create
a
using the default constructor.
In both cases, there must be an accessible copy constructor, even if it is not actually used.
2)
ABC a;
That will create a
using the default constructor.
ABC b = ABC();
That will do the same as in question 1; it's up to the compiler whether to elide the copy.
So the first form could potentially be more efficient, if the compiler doesn't perform that particular optimisation, and if copying a default-initialised object is expensive.