Compiler Error C2864
'variable' : only static const integral data members can be initialized within a class
You attempted to initialize a data member that was not defined as const and static.
The following sample generates C2864:
// C2864.cpp
class B {
int i = 3; // C2864;
static const int i = 3; // OK
};
The following sample generates C2864:
// C2864b.cpp
// compile with: /c
#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
// Uncomment the following 2 lines to resolve.
// BaseCls * BObj;// = new DervCls;
// DervCls * DObj;// = new DervCls;
void ShowZ() {
// Uncomment the following 2 lines to resolve.
// BObj = new DervCls;
// DObj = new DervCls;
printf("Accessed via base class: %d", BObj->Z);
printf("Accessed via derived class: %c", DObj->Z);
}
};