static const member variables

Started by
5 comments, last by zoner7 14 years, 8 months ago
I received the following errors while trying to compile my program: error C2864: 'GameStates::PlayGameState::firstTry' : only static const integral data members can be initialized within a class The error occurs on the line "bool firstTry = true;" Since I have plenty of variables above this call that work just fine, I'm going to take a guess that the error has to do with the bool type. I only say this because the firstTry declaration is the only bool variable declared. Am I on the right track here?
Advertisement
It might have something to do with missing the static and const keywords.
I understand that... but why are their inclusions necessary?

furthermore, what am I suppose to do if I don't want the variable to be constant.
Standard fiat. That's just the way the language is defined. It gets changed in C++0x, but you apparently aren't using a C++0x compiler.
class PlayGameState{public:    PlayGameState() : firstTry(true){}    /*...*/bool firstTry; };



Use an initialization list to initialize variables in classes.
Quote:Original post by zoner7
furthermore, what am I suppose to do if I don't want the variable to be constant.


Just don't initialize your variables within the class declaration. Have the constructor set it to true.

EDIT: like caldiar said.
oops, that's right. I'm sorry, I had a huge brain fart. I guess that's what happens when you code late late at night.

Thank you both

This topic is closed to new replies.

Advertisement