编译器警告(等级 2)C4345

更新:2007 年 11 月

错误消息

行为更改: 使用 () 形式的初始值设定项构造的 POD 类型的对象将被默认初始化

此警告报告使用 () 初始化 POD 对象时从 Visual Studio .NET 中附带的 Visual C++ 编译器上发生行为更改;该编译器将默认初始化该对象。

有关更多信息,请参见编译时的重大更改摘要

下面的示例生成 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);
}