Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Compiler Error C2866

'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 {
   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 {
   const static double d;   // C2866
   const static double d2 = 9;   // OK

Community Additions

© 2015 Microsoft