This documentation is archived and is not being maintained.

Compiler Error C2866

Error Message

'variable' : a const static data member of a managed type must be initialized at the point of declaration

It is invalid to declare an uninitialized, const static data member in a managed class or struct.

The following sample generates C2866:

// C2866.cpp
// compile with: /clr /c
ref class x {
public:
   const static int i;   // C2866
   const static int j = 0;   // OK

   // Delete the following line to resolve.
   void xx() { i = 9; }
};

The following sample generates C2866:

// C2866b.cpp
// compile with: /clr:oldSyntax /c

__gc class CMyClass {
public:
   const static double d;   // C2866
   const static double d2 = 9;   // OK
};
Show: