分享方式:


編譯器警告 (層級 3) C4398

' variable ' :個別進程全域物件可能無法與多個 appdomain 正確運作;請考慮使用 __declspec(appdomain)

備註

原生類型中具有 __clrcall 呼叫慣例的虛擬函式會導致建立每個應用程式域 vtable。 在多個應用程式域中使用時,這類變數可能無法正確更正。

您可以藉由明確標記 變數 __declspec(appdomain) 來解決此警告。 在 Visual Studio 2017 之前的 Visual Studio 版本中,您可以使用 /clr:pure 進行編譯 來解決此警告,預設會讓每個 appdomain 產生全域變數。 Visual Studio 2015 中已淘汰 /clr:pure 編譯器選項,Visual Studio 2017 不支援。

如需詳細資訊,請參閱 appdomain Application Domains 和 Visual C++

範例

下列範例會產生 C4398。

// C4398.cpp
// compile with: /clr /W3 /c
struct S {
   virtual void f( System::String ^ );   // String^ parameter makes function __clrcall
};

S glob_s;   // C4398
__declspec(appdomain) S glob_s2;   // OK