Re: [Dev-C++] Problems with pointers to member functions
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2003-02-18 23:32:49
|
See below. EMA System email: pw...@ia... Per Westermark web: http://iapetus.neab.net Vargvaegen 174B phone: +46 8 410 17 198 S-906 42 Umeaa Sweden On Tue, 18 Feb 2003, Tulius Lima wrote: > 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; > } And what will action be initialized to if none of the four if statements above are valid? > > (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 > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |