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:
struct StateStruct
{
typedef void (*StatePointer)();
};
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,
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();
}
}
I've created a method Exit() of the App
void App::Exit()
{
cout << "I am exiting game." << endl;
stateStack.pop();
}
and now in App::Init(), I try to use
StateStruct state;
state.StatePointer = Exit; // <-- DevCPP throws out error here
// state.StatePointer =&App::Exit; gives same error as the line above
stateStack.push(state);
the error is "invalid use of `StateStruct::StatePointer'"
oh yeah,
stack<StateStruct> stateStack; // application's state stack
is a private member variable of class App.
I _really_ have no idea what to do now. Any help will be appreciated.
If only noobs were boobs... the world would be a better place.