Sign in to follow this  
zoner7

static const member variables

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

class PlayGameState{
public:
PlayGameState() : firstTry(true){}

/*...*/

bool firstTry;
};





Use an initialization list to initialize variables in classes.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this