2

Look at the tow declarations bellow. These two method make any different in C++ 11? I checked the story about C++03 here

Class A{int m;}

  1. A* a = new A
  2. A* a = new A();
Community
  • 1
  • 1
Nayana Adassuriya
  • 23,596
  • 30
  • 104
  • 147

1 Answers1

9

It's the same in C++11 as it was in C++03.

The first is default-initialision, leaving m uninitialised.

The second is value-initialisation, initialising m to zero.

If the class had a user-provided default constructor, then both would do the same thing, calling that constructor.

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644