Original Post
I'm creating an application that runs as a stack: exit->menu->game. every part of a stack is a separate function. since STL stack cannot use function pointers, i wrap it like that: It run fine when the Exit(), Menu() and Game() functions were global, but I decided to try to change it to oop (and here came the uglies) I have class App, containing basically whole my program, I've created a method Exit() of the App and now in App::Init(), I try to use the error is "invalid use of `StateStruct::StatePointer'" oh yeah, is a private member variable of class App. I _really_ have no idea what to do now. Any help will be appreciated.
struct StateStruct
{
typedef void (*StatePointer)();
};
int main(int argc, char *argv[])
{
App *MyDemo = new App;
MyDemo->MainLoop();
delete MyDemo;
return 0;
}
void App::MainLoop()
{
while (!stateStack.empty())
{
stateStack.top().StatePointer();
}
}
void App::Exit()
{
cout << "I am exiting game." << endl;
stateStack.pop();
}
StateStruct state;
state.StatePointer = Exit; // <-- DevCPP throws out error here
// state.StatePointer =&App::Exit; gives same error as the line above
stateStack.push(state);
stack<StateStruct> stateStack; // application's state stack