编译器错误 C2441

variable':使用 __declspec(process) 声明的符号必须是 /clr:pure 模式中的常量

注解

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

默认变量是 /clr:pure 下的每个应用程序域。 在 /clr:pure 中标记为 __declspec(process) 的变量,如果在一个应用程序域中修改而在另一个应用程序域中读取,很容易出错。

因此,编译器强制每个进程变量为 /clr:pure 下的 const,使其在所有应用程序域中只读。

有关详细信息,请参阅进程/clr(公共语言运行时编译)

示例

以下示例生成 C2441。

// C2441.cpp
// compile with: /clr:pure /c
__declspec(process) int i;   // C2441
__declspec(process) const int j = 0;   // OK