• Announcements

Archived

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

static int in c++ ????

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 on other sites
You have to initialize it first.
class A{	public :	static int myVar;};// outside the class, possibly in a source (.cpp) fileint A::myVar = 0;

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

• Forum Statistics

• Total Topics
627711
• Total Posts
2978746

• 21
• 14
• 12
• 36
• 30