[SDL] Tryig to use SDL_audio in a class structure
Ricardo Cruz
rpmcruz at clix.pt
Sat Jul 22 16:22:35 PDT 2006
Hi everyone,
I think what Lilith meant was something like this, no?
class MyClass
{
MyClass()
{ setup_callback (value_changed_cb, this); }
static void value_changed_cb (MyClass *pThis)
{
pThis->whatever();
// you may access even private members of course
}
};
I am in a project where I use C++ and plain GTK+, and GTK+ use callbacks for
events, so the code would be quite a pain to read the way you deal with
callbacks.
Cheers,
Ricardo
Em Sábado, 22 de Julho de 2006 17:48, o Peter Mulholland escreveu:
> Lilith Calbridge wrote:
> > Can you not take the Windows tactic of declaring the callback function
> > as a static member? That leaves one "shared" instance of the function
> > for all objects of the class.
>
> I think you can do this, but then you don't get access to any class
> member variables as there is no way to know which instance of the class
> to use. That is why you have to do a redirect, storing the "this"
> pointer for that class in some user-data pointer.
>
> You can create a certain kind of class called a Singleton which
> guarantees that all instances of a class refer to one single object, but
> that still requires you to bounce callbacks as shown here.
>
> In fact, this is one of the flaws I find in SDL_mixer, which has
> callbacks for things like "Music finished" and "Channel finished", but
> no user data field, making them unusable from a C++ class. It's one
> thing I'd like to see added to SDL_mixer at some point.
>
> Pete.
>
--
Let He who taketh the Plunge Remember to return it by Tuesday.
More information about the SDL
mailing list