Compiler Error C2864
This page is specific to:.NET Framework Version:1.12.03.03.54.0
Visual C++ Concepts: Building a C/C++ Program
Compiler Error C2864

'variable' : only const static integral data members can be initialized inside a class or struct

You attempted to initialize a nonstatic data member.

The following sample generates C2864:

// C2864.cpp
class B  {
int i = 3;   // C2864; 
// try ...
// static const int i = 3;
};

The following sample generates C2864:

// C2864b.cpp
// compile with: /LD
#include <stdio.h>
class BaseCls
{
public:
   int Z;
 };

class DervCls : public BaseCls
{
public:
   char Z;
};

class UseClasses
{
public:
   BaseCls * BObj = new DervCls;   // C2864
   DervCls * DObj = new DervCls;   // C2864 
   // try the following lines instead
   // BaseCls * BObj;// = new DervCls;   // C2864
   // DervCls * DObj;// = new DervCls;   // C2864 

   void ShowZ()
   {
      // also uncomment these lines
      // BObj = new DervCls;
      // DObj = new DervCls;
      printf("Accessed via base class: %d", BObj->Z);
      printf("Accessed via derived class: %c", DObj->Z);
   }
};
© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View