Take the 2-minute tour ×

If 'Test' is an ordinary class, is there any difference between:

Test* test = new Test;
Test* test = new Test();
share|improve this question
+1 I wouldn't have even thought to ask this question. I just assumed they had the same behavior. –  Matt Davis Jun 30 '10 at 21:52
This is related to (but not identical to) stackoverflow.com/questions/1613341/… –  Steve Jessop Dec 7 '10 at 17:21

5 Answers 5

up vote 548 down vote accepted

Let's get pedantic, because there are differences that can actually affect your code's behavior. Much of the following is taken from comments made to an "Old New Thing" article.

Sometimes the memory returned by the new operator will be initialized, and sometimes it won't depending on whether the type you're newing up is a POD (plain old data), or if it's a class that contains POD members and is using a compiler-generated default constructor.

  • In C++1998 there are 2 types of initialization: zero and default
  • In C++2003 a 3rd type of initialization, value initialization was added.


struct A { int m; }; // POD
struct B { ~B(); int m; }; // non-POD, compiler generated default ctor
struct C { C() : m() {}; ~C(); int m; }; // non-POD, default-initialising m

In a C++98 compiler, the following should occur:

  • new A - indeterminate value
  • new A() - zero-initialize

  • new B - default construct (B::m is uninitialized)

  • new B() - default construct (B::m is uninitialized)

  • new C - default construct (C::m is zero-initialized)

  • new C() - default construct (C::m is zero-initialized)

In a C++03 conformant compiler, things should work like so:

  • new A - indeterminate value
  • new A() - value-initialize A, which is zero-initialization since it's a POD.

  • new B - default-initializes (leaves B::m uninitialized)


  • new C - default-initializes C, which calls the default ctor.

  • new C() - value-initializes C, which calls the default ctor.

So in all versions of C++ there's a difference between "new A" and "new A()" because A is a POD.

And there's a difference in behavior between C++98 and C++03 for the case "new B()".

This is one of the dusty corners of C++ that can drive you crazy. When constructing an object, sometimes you want/need the parens, sometimes you absolutely cannot have them, and sometimes it doesn't matter.

share|improve this answer
I had to look up POD. stackoverflow.com/questions/146452/what-are-pod-types-in-c –  Derek Jan 24 '10 at 19:09
Sorry about that - I sometimes forget that "POD" might not be understood by all C++ programmers. It is something that is good for every C++ programmer to know, though - there are important distinctions that a C++ compiler can (or must) make for plain-old-data types. Thanks for the pointer to a good description. –  Michael Burr Jan 24 '10 at 19:54
This answer is awesome. –  GManNickG Apr 16 '10 at 4:32
@j_random_hacker, new A() will default-initialize the object in C++98, like it does with new B(), new B, new C() and new C, but not with new A. That is, default initialization is always done in C++98 when either: 1) The class is a non-POD and the initializer is missing, or 2) The initializer is (). default-initialization zero-initializes the object if it's a POD, but calls the default constructor for non-PODs. –  Johannes Schaub - litb Jan 2 '11 at 13:32
Can someone add what is the case in C++11 now? –  legends2k Aug 21 '12 at 4:39

Assuming that Test is a class with a defined constructor, there's no difference. The latter form makes it a little clearer that Test's constructor is running, but that's about it.

share|improve this answer

No, they are the same. But there is a difference between:

Test t;      // create a Test called t


Test t();   // declare a function called t which returns a Test

This is because of the basic C++ (and C) rule: If something can possibly be a declaration, then it is a declaration.

Edit: Re the initialisation issues regarding POD and non-POD data, while I agree with everything that has been said, I would just like to point out that these issues only apply if the thing being new'd or otherwise constructed does not have a user-defined constructor. If there is such a constructor it will be used. For 99.99% of sensibly designed classes there will be such a constructor, and so the issues can be ignored.

share|improve this answer
Note that this is a particularly important point because the line "Test t(5);" is equivalent to "Test t = Test(5);" -- but "Test t();" is very different from "Test t = Test();". +1 –  ojrac Mar 6 '09 at 20:03
-1, I disagree with your statement that the issues can be ignored. You don't have to know the rules precisely, but you should be aware of them in case you have to new a class without a user-defined default constructor (you should then either write the constructor or look up the rules). –  avakar Mar 6 '10 at 7:02
-1 for a known incorrect answer. Your Edit ignores the presence of code written by former C programmers who didn't understand/use constructors. –  Tom Apr 16 '10 at 11:00
What about classes like struct point { float v[3]; };? For things like that, a constructor would be a bad idea, as it would prevent all the nice properties that come with being POD and aggregate. So "the issues can be ignored" is just wrong, imo. –  me22 Jan 2 '11 at 3:56
But they are not the same. This answer is plain wrong. It should be fixed or removed, because it seems to have caused some confusion, judging by the high number of up-votes. –  juanchopanza Aug 11 '14 at 5:59

In general we have default-initialization in first case and value-initialization in second case.

For example: in case with int (POD type):

  • int* test = new int - we have any initialization and value of *test can be any.

  • int* test = new int() - *test will have 0 value.

next behaviour depended from your type Test. We have defferent cases: Test have defult constructor, Test have generated default constructor, Test contain POD member, non POD member...

share|improve this answer

new Thing(); is explicit that you want a constructor called whereas new Thing; is taken to imply you don't mind if the constructor isn't called.

If used on a struct/class with a user-defined constructor, there is no difference. If called on a trivial struct/class (e.g. struct Thing { int i; };) then new Thing; is like malloc(sizeof(Thing)); whereas new Thing(); is like calloc(sizeof(Thing)); - it gets zero initialized.

The gotcha lies in-between:

struct Thingy {
  ~Thingy(); // No-longer a trivial class
  virtual WaxOn();
  int i;

The behavior of new Thingy; vs new Thingy(); in this case changed between C++98 and C++2003. See Michael Burr's explanation for how and why.

share|improve this answer

Your Answer


