Delen via


Compilerfout C3883

Lid: een initonly statisch gegevenslid moet worden geïnitialiseerd

Opmerkingen

Een variabele die is gemarkeerd met initonly , is niet correct geïnitialiseerd.

Example

In het volgende voorbeeld wordt C3883 gegenereerd:

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

In het volgende voorbeeld ziet u een mogelijke oplossing:

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

In het volgende voorbeeld ziet u hoe u initialiseert in een statische constructor:

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

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