分享方式:


編譯器錯誤 C3898

'var' :類型資料成員只能是 Managed 類型的成員

原生類別中宣告了 Initonly 資料成員。 initonly資料成員只能在 CLR 類別中宣告。

下列範例會產生 C3898:

// C3898.cpp
// compile with: /clr
struct Y1 {
   initonly
   static int data_var = 9;   // C3898
};

可能的解決方式:

// C3898b.cpp
// compile with: /clr /c
ref struct Y1 {
   initonly
   static int data_var = 9;
};