編譯器錯誤 C2441
'variable' :以 __declspec(process) 宣告的符號必須是 /clr:pure 模式中的 const
備註
Visual Studio 2015 中已淘汰 /clr:pure 和 /clr:safe 編譯程序選項,且 Visual Studio 2017 不支援。
根據預設,變數是 /clr:pure 下每個應用程式域。 在 /clr:pure 底下標示__declspec(process)
的變數在一個應用程式域中修改並讀取另一個應用程式域時,很容易發生錯誤。
因此,編譯程式會強制每個進程變數位於 const
/clr:pure 底下,使其在所有應用程式域中都是唯讀的。
如需詳細資訊,請參閱 process 和 /clr (Common Language Runtime Compilation)。
範例
下列範例會產生 C2441。
// C2441.cpp
// compile with: /clr:pure /c
__declspec(process) int i; // C2441
__declspec(process) const int j = 0; // OK