编译器错误 C2434

“symbol”:使用 __declspec(process) 声明的符号不能以 /clr:pure 模式动态初始化

注解

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

无法在 /clr:pure 下动态初始化每进程变量。 有关详细信息,请参阅 /clr(公共语言运行时编译)process

示例

以下示例生成 C2434。 若要解决此问题,请使用常量来初始化 process 变量。

// C2434.cpp
// compile with: /clr:pure /c
int f() { return 0; }
__declspec(process) int i = f();   // C2434
__declspec(process) int i2 = 0;   // OK