delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/18/12:02:28

From: Martynas Kunigelis <algikun AT santaka DOT sc-uni DOT ktu DOT lt>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allegro Timers
Date: Sat, 18 Jan 1997 13:32:41 +0000
Organization: LITNET
Lines: 47
Message-ID: <Pine.HPP.3.95.970118132632.8186A-100000@santaka.sc-uni.ktu.lt>
References: <fgtLCdAvIM3yEwIZ AT flag DOT demon DOT co DOT uk> <5DP9XEAWk93yEwfW AT talula DOT demon DOT co DOT uk>
NNTP-Posting-Host: santaka.sc-uni.ktu.lt
Mime-Version: 1.0
In-Reply-To: <5DP9XEAWk93yEwfW@talula.demon.co.uk>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp


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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019