statics in a class

hi guys.

it seems everytime i use statics in a class i come across with a porblem.

this time i wanted to make a class i created static inside another class.

MainVariables.h file
static fge::window mWinMain;


if someone ever wants to reach it
MainVariables.cpp file
1
2
3
4
5
6
7
fge::window MainVariables::mWinMain;
...
...
fge::window MainVariables::GetWinMain()
{
    return mWinMain;
}


but when i created some other MainVariables classes at other places instead of them reaching to the same window two window is being created.

yes i know maybe there are better methods but currently i m working on polymorphism and i need some static members. so i need to resolve it to fix my problem.

thx for your helps in advance

EDIT: pls correct me if i know wrong some stuffs
Last edited on
"but when i created some other MainVariables classes at other places"
This statement seems to imply that your are creating other classes with static variables of the same name. Static variables are only shared across the class your accessing, and defining static variables with similar names in other locations will point to another variable.
ok thx then

i changed the functions to static and call them like MainVariables::GetWinMain(); which seems like solved the problem. i will test if it did or not.

anyways thx for your helps
Topic archived. No new replies allowed.