Compilerfehler C3883

"member": Ein initonly static data member muss initialisiert werden

Bemerkungen

Eine variable, die mit "initonly " markiert wurde, wurde nicht richtig initialisiert.

Example

Im folgenden Beispiel wird C3883 generiert:

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

Im folgenden Beispiel wird eine mögliche Auflösung veranschaulicht:

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

Das folgende Beispiel zeigt, wie Sie in einem statischen Konstruktor initialisieren:

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

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