4

Is there any difference between A a; and A a = A()? Here A is a class.

JunGor
  • 363
  • 2
  • 10

1 Answers1

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
  • 138,963
  • 15
  • 198
  • 315