Per,
You were right!
I just appended a
} else {
action = &Sprite::stop;
}
and the thing worked.
Excuse me while I'll put my diploma through the shredder.
Thanks for you help!
Tulius
>From: Per Westermark <pw...@ia...>
>To: Tulius Lima <tul...@ho...>
>CC: wo...@Ne..., <dev...@li...>
>Subject: Re: [Dev-C++] Problems with pointers to member functions
>Date: Wed, 19 Feb 2003 00:31:24 +0100 (CET)
>
>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
> >
>
_________________________________________________________________
MSN Hotmail, o maior webmail do Brasil. http://www.hotmail.com
|