Teilen über


Compilerfehler C2864

'Membername': Ein statisches Datenmemm mit einem In-Class-Initializer muss einen nicht veränderlichen Integraltyp aufweisen.

Hinweise

Verwenden Sie zum Initialisieren eines static Datenmembes, das als volatilenicht, nichtconst oder nicht als integraler Typ definiert ist, eine Memberdefinitionsanweisung. Sie können in einer Deklaration nicht initialisiert werden.

Beispiel

In diesem Beispiel wird C2864 generiert:

// C2864.cpp
// compile with: /c
class B  {
private:
   int a = 3;   // OK
   static int b = 3;   // C2864
   volatile static int c = 3;   // C2864
   volatile static const int d = 3;   // C2864
   static const long long e = 3;   // OK
   static const double f = 3.33;   // C2864
};

In diesem Beispiel wird gezeigt, wie C2864 behoben wird:

// C2864b.cpp
// compile with: /c
class C  {
private:
   int a = 3;
   static int b; // = 3; C2864
   volatile static int c; // = 3; C2864
   volatile static const int d; // = 3; C2864
   static const long long e = 3;
   static const double f; // = 3.33; C2864
};

// Initialize static volatile, non-const, or non-integral
// data members when defined, not when declared:
int C::b = 3;
volatile int C::c = 3;
volatile const int C::d = 3;
const double C::f = 3.33;