Mail Archives: djgpp/1997/01/18/12:02:28
On Fri, 17 Jan 1997, Shawn Hargreaves wrote:
>
> Not easily. C++ class members take a 'hidden' parameter which is a
> pointer to the object, so calling class.member() is really the same as
> writing member(&class) in C. Allegro has no way of knowing about this
> hidden parameter, so the call won't work.
>
> The easy workaround is to make the member function static, so it won't
> have the hidden parameter. Alternatively, write a wrapper function to
> use as the timer callback, eg:
>
> class myobject;
>
> void wrapper()
> {
> myobject.member();
> }
>
Shawn, what if you want to set many callbacks? Writing 'many' wrappers is
not a reasonable solution. A good solution IMHO would be if the
SetCallback or whatever function took a parameter void *UserData, and then
pass this parameter to the callback handler. Then you could pass the
address of the object when setting the callback and the wrapper would look
like this:
void wrapper(void *data)
{
((myclass *)data)->member();
}
and you would be able to have one wrapper for many objects, and make it a
static member function actually.
I know this implies changing the API, but that's just a theoretical
suggestion and you might consider it doing further development.
P.S. I can't wait for Linux-GGI (General Graphics Interface) to show up,
so a port of Allegro to Linux would be possible!
Martynas
- Raw text -