Erreur du compilateur C3883

'member' : un membre de données statique initonly doit être initialisé

Remarques

Une variable marquée avec initonly n’a pas été initialisée correctement.

Example

L’exemple suivant génère l’erreur C3883 :

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

L’exemple suivant illustre une résolution possible :

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

L’exemple suivant montre comment initialiser dans un constructeur statique :

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

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