23

Possible Duplicate:
Do the parentheses after the type name make a difference with new?

So I had in my main:

Class* pC = new Class;

It was working as

Class* pC = new Class();

I realized just today that I had omitted the parentheses (so I was hit by the "opposite" of the most vexing parse in a way).

My question: Are these two forms equivalent ?

Community
  • 1
  • 1
Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361

1 Answers1

50

If the class has a default constructor defined, then both are equivalent; the object will be created by calling that constructor.

If the class only has an implicit default constructor, then there is a difference. The first will leave any members of POD type uninitialised; the second will value-initialise them (i.e. set them to zero).

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