Is there any difference between A a
; and A a = A()
?
Here A
is a class.
Asked
Active
Viewed 151 times
1 Answers
6
There is a formal difference between direct initialization syntax
A a;
and copy initialization syntax
A a = A();
in that the latter allows a call of the A
copy or move constructor, and requires that there is an accessible copy constructor or move constructor.
However, in practice that extra constructor call will be elided.

Cheers and hth. - Alf
- 142,714
- 15
- 209
- 331
-
1The second also results with a value-initialized object `a`, which may or may not matter, depending on `A`. – juanchopanza Apr 16 '16 at 06:52