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
  • 21,894
  • 22
  • 97
  • 139

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
  • 242,813
  • 27
  • 432
  • 630