编译器警告(等级 1)C4965

整数 0 的隐式装箱;请使用 nullptr 或显式强制转换

值类型的隐式装箱是 Visual C++ 的特点。 使用 Managed Extensions for C++ 完成 null 赋值的指令现在将成为装箱整数赋值。

有关更多信息,请参见 装箱中定义的接口的私有 C++ 特定实现。

示例

下面的示例生成 C4965。

// C4965.cpp
// compile with: /clr /W1
int main() {
   System::Object ^o = 0;   // C4965

   // the previous line is the same as the following line
   // using Managed Extensions for C++
   // System::Object *o = __box(0);

   // OK
   System::Object ^o2 = nullptr;
   System::Object ^o3 = safe_cast<System::Object^>(0);
}