Mix_HookMusicFinished() and C++ function pointers

Hello,
I’m playing around with SDL_mixer a bit and have ran into a problem.

My mission is to write a kind of simplifiying SND_Server class, which wraps
the most essential functionality of SDL_mixer.

A simplified version of the class looks like this:

class SND_Server
{
public:
void StartMusic();

private:
// A private helper function.
void SetNotPlaying();

bool MusicIsPlaying;

};

void SND_Server::StartMusic()
{
StartTheMusicInc();

/*** HERE'S THE PROBLEM **/
// In what "format" should I give MixHookMusicFinished()
// function pointer to SetNotPlaying which is a member of 
// this class?
Mix_HookMusicFinished(SND_Server::SetNotPlaying);

}

The only way I’ve got the code to compile and link is if I declare
MusicIsPlaying and SetNotPlaying() as static, but when I run the program
(starting the music with Mix_PlayMusic(m, 0)) SetNotPlaying is never called.

Someone must have had the same problem as I and solved, so I would
appreciate help.

Greetings,
Viktor Stansvik

Take a look into sigc++
it’s a library to implement signals and callbacks in c++

it allows you to register a callback function if it is a non static
method.

El 2003.08.15 08:59, Viktor Stansvik escribi?:> Hello,

I’m playing around with SDL_mixer a bit and have ran into a problem.

My mission is to write a kind of simplifiying SND_Server class, which
wraps
the most essential functionality of SDL_mixer.

A simplified version of the class looks like this:

class SND_Server
{
public:
void StartMusic();

private:
// A private helper function.
void SetNotPlaying();

bool MusicIsPlaying;

};

void SND_Server::StartMusic()
{
StartTheMusicInc();

/*** HERE'S THE PROBLEM **/
// In what "format" should I give MixHookMusicFinished()
// function pointer to SetNotPlaying which is a member of
// this class?
Mix_HookMusicFinished(SND_Server::SetNotPlaying);

}

The only way I’ve got the code to compile and link is if I declare
MusicIsPlaying and SetNotPlaying() as static, but when I run the
program
(starting the music with Mix_PlayMusic(m, 0)) SetNotPlaying is never
called.

Someone must have had the same problem as I and solved, so I would
appreciate help.

Greetings,
Viktor Stansvik


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl