次の方法で共有


コンパイラの警告 (レベル 2) C4345

更新 : 2007 年 11 月

エラー メッセージ

動作変更 : 形式 () の初期化子で構築される POD 型のオブジェクトは既定で初期化されます。

この警告は、POD オブジェクトを () で初期化する場合に、Visual Studio .NET に付属している Visual C++ コンパイラの動作変更を報告します。コンパイラは、既定でオブジェクトを初期化します。

詳細については、「Summary of Compile-Time Breaking Changes」を参照してください。

次の例では 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);
}