Sign in to follow this  

static const member variables

This topic is 3041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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

This topic is 3041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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