Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Compiler Warning (level 2) C4345
Collapse the table of content
Expand the table of content

Compiler Warning (level 2) C4345

Error Message

behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized

This warning reports a behavior change from the Visual C++ compiler that shipped in Visual Studio .NET when initializing a POD object with (); the compiler will default-initialize the object.

See Summary of Compile-Time Breaking Changes for more information.

The following sample generates C4345:

// C4345.cpp
// compile with: /W2
#include <stdio.h>

struct S* gpS;

struct S
   // this class has no user-defined default ctor
   void *operator new (size_t size, void*p, int i)
      ((S*)p)->i = i;   // ordinarily, should not initialize
                        // memory contents inside placement new
      return p;
   int i;

int main()
   S s;
   // Visual C++ .NET 2003 will default-initialize pS->i
   // by assigning the value 0 to pS->i.
   S *pS2 = new (&s, 10) S();   // C4345
   // try the following line instead
   // S *pS2 = new (&s, 10) S;   // not zero initialized
   printf("%d\n", pS2->i);

Community Additions

© 2015 Microsoft