编译器警告 C4959

不能在 /clr:safe 中定义非托管结构“type”,因为访问其成员会产生不可验证的代码

备注

访问非托管类型的成员会生成无法验证的 (peverify.exe) 映像。

有关详细信息,请参阅纯代码和可验证代码 (C++/CLI)

“/clr:safe”编译器选项在 Visual Studio 2015 中已弃用,并且在 Visual Studio 2017 中不受支持

此警告作为错误发出,可通过 warning 杂注或 /wd 编译器选项禁用该警告。

示例

下面的示例生成 C4959:

// C4959.cpp
// compile with: /clr:safe

// Uncomment the following line to resolve.
// #pragma warning( disable : 4959 )
struct X {
   int data;
};

int main() {
   X x;
   x.data = 10;   // C4959
}