[Dev-C++] Problems with pointers to member functions
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Tulius L. <tul...@ho...> - 2003-02-18 20:41:35
|
Hi Folks,
I've been trying to work with pointers to member functions (after I
saw the code posted by Japp de Wolff) to implement a finite-state machine
for a SDL sprite engine.
After a few bumps I managed to compile the code. But it crashes when
it runs (when it hits the member function).
Can anyone tell me please what's wrong with my code?
TIA
Tulius Lima
------------
typedef void (Sprite::*Action)();
class Sprite
{
public:
// operations
void moveUp();
void moveDown();
void moveLeft();
void moveRight();
void stop();
void move();
};
int main(int argc, char *argv[])
{
Sprite ship;
Action action;
Uint8* keys;
// SDL code omitted
int done = 0;
while (!done)
{
keys = SDL_GetKeyState(NULL);
if ( keys[SDLK_UP] )
{
action = &Sprite::moveUp;
}
if ( keys[SDLK_DOWN] )
{
action = &Sprite::moveDown;
}
if ( keys[SDLK_LEFT] )
{
action = &Sprite::moveLeft;
}
if ( keys[SDLK_RIGHT] )
{
action = &Sprite::moveRight;
}
(ship.*action)(); // <--- problematic code
SDL_Flip(screen);
}
// SDL finalization code omitted
return 0;
}
-------------------- end
_________________________________________________________________
MSN Hotmail, o maior webmail do Brasil. http://www.hotmail.com
|