1

Under C++11, if 'Test' is an ordinary class, is there any difference between:

Test* test = new Test;
//and
Test* test = new Test();

Note: this is the same question Do the parentheses after the type name make a difference with new? asked again, because the old thread is before C++11, while I'd like to ask if there's a difference under c++11 stadard.

The accepted answer of that question says:

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

I understand that C++11 only has 2 initialization, default and value. So i fancy the answer are a bit different?

Community
  • 1
  • 1
athos
  • 6,120
  • 5
  • 51
  • 95

1 Answers1

1

C++11 has zero-initialization, default-initialization, value-initialization (8.5/5, /6 and /7, correspondingly), copy-initialization (8.5/14), direct-initialization (8.5/15) and list-initialization (8.5.4).

With respect to new in particular:

5.3.4/15 A new-expression that creates an object of type T initializes that object as follows:

— If the new-initializer is omitted, the object is default-initialized (8.5); if no initialization is performed, the object has indeterminate value.

— Otherwise, the new-initializer is interpreted according to the initialization rules of 8.5 for direct-initialization.

Igor Tandetnik
  • 50,461
  • 4
  • 56
  • 85
  • Oh! I didn't know there's "zero-initialization" in C++11 -- as far as I could remember "C++ Primer" seems only introduced default and value initialization. May I ask what is "8.5/5"? Where could I check the detailed content? – athos Dec 30 '14 at 05:08