Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

EkEk

static int in c++ ????

This topic is 5310 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 have this problem. i tried to make a static variabel in class in c++ like in java, like KeyEvent.VK_ESCAPE. so i can use variabel from the class without declare an object.
class A{
  public :
    static int myVar;
};
 
just like that. is it posible if i do something like this
void main(){
  cout << A :: myVar; // or A.myVar
}
 
just like in java KeyEvent.VK_ESCAPE how can i do this?? because above code are error. can someone give a suggestion??

Share this post


Link to post
Share on other sites
Advertisement
You have to initialize it first.

class A
{
public :
static int myVar;
};

// outside the class, possibly in a source (.cpp) file

int A::myVar = 0;

Share this post


Link to post
Share on other sites
a very stupid mistake of mine...
i''ve tried to do like you did
but i forgot to add int in the front

A :: myVar = 1; //without int


thank you very very much....

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!