www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/16/19:22:51

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


On Wed, 15 Jan 1997, Moo-Juice wrote:

> Hi,
> 
> I've been having some trouble installing timers in Allegro, using a
> public class member function as the argument.
> 
> Supplying a standard function as the parameter works, but if I pass a
> class member function it doesn't like it at all.  Is there a work around
> for this?
> 

Because a member function has a hidden parameter -- the 'this' pointer.
In C world, a Object.Member(int parameter) looks like ObjectMember(Class
*this, int parameter), while Allegro wants a function that takes integer
only (dunno the exact case, this is an example only). You must use a
static member function for that, but Allegro should provide some kind of
user data parameter for the callback, so you could pass the 'this' pointer
explicitly, e.g. (note I've never used allegro):

class thingy {
private:
  static void timerCallback(int timeout, void *object)
  {
    ((thingy *) object)->handleTimerCallback(timeout);
  }

  void handleTimerCallback(int timeout)
  {
    // the actual code..
  }

};

void allegro_set_timer_callback(int a, int b, fnptr callback, void *userdata);

main()
{
 ....

 thingy myThingy;

 allegro_set_timer_callback(xx, yy, myThingy.timerCallback, &myThingy);
}

now, I don't know if Allegro provides the user data parameter for
callbacks, but most C frameworks do, and mostly just for situations like
yours, i.e. possibility to build C++ wrappers.

P.S. good luck to all DJGPPers, it's great.

Martynas


 
 

- Raw text -


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