Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Compiler Error C2864
Collapse the table of content
Expand the table of content

Compiler Error C2864

'variable' : a static data member with an in-class initializer must have non-volatile const integral type

To initialize a static data member that is defined as volatile, non-const, or not an integral type, use a member-definition statement. They cannot be initialized in a declaration.

This sample generates C2864:

// 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
   const static long long e = 3;   // OK
   static const double f = 3.33;   // C2864
};

This sample shows how to fix C2864:

// 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;
Show:
© 2015 Microsoft