I am making some game and I get following error :
class Apple:public Fruit{
public:
bool isAppleOK = false;
Apple(int amount, int pHValue) {
amount = amount;
pHValue= pHValue;
} ~Apple() {
}
/*code trimmed*/
error C2864: ‘Apple::isAppleOK ‘ : only static const integral data members can be initialized within a class
What am I missing here?
This is not the way you initialize member variables in C++. You need to set the value in the init list of the constructor:
You can also move the initialization of your other variables into the initialization list: