編譯器錯誤 C3883

'member':必須初始化initonly靜態資料成員

備註

未正確初始化標示 為 initonly 的變數。

Example

下列範例會產生 C3883:

// C3883.cpp
// compile with: /clr
ref struct Y1 {
   initonly
   static int staticConst1;   // C3883
};

下列範例示範可能的解決方案:

// C3883b.cpp
// compile with: /clr /c
ref struct Y1 {
   initonly
   static int staticConst2 = 0;
};

下列範例示範如何在靜態建構函式中初始化:

// C3883c.cpp
// compile with: /clr /LD
ref struct Y1 {
   initonly
   static int staticConst1;

   static Y1() {
      staticConst1 = 0;
   }
};