1) As written, this is a function declaration; you need to modify it a bit to get the behavior you plan:
ABC a((ABC()));
or
ABC a = ABC();
In this case, the compiler has two options:
- Create a temporary object using the default constructor and initialize
a using the copy constructor; - Return the copy and create
a using the default constructor.
In both cases, there must be an available copy constructor, even if it is not actually used.
2)
ABC a;
This will create a using the default constructor.
ABC b = ABC();
This will do the same as in question 1; it is up to the compiler whether to delete the copy.
Thus, the first form could potentially be more efficient if the compiler does not perform this particular optimization, and if copying the default initialized object is expensive.
source share