From: Lawrence E Bertoldi (lberto++at++adelphia.net)
Date: 08/13/2004 06:55:33
You need to use a "static" wrapper for the callback.
here is an example of how I do it in a Vehicle class I wrote
your case is slightly different but the theory is the same!
in the public part of the class header I declare the pre and post methods as static
i.e. there is only one method for the whole class:
class PFTL_Vehicle
public:
//*** these are the static callbacks that all instances of the class use to access
//*** the real callbacks
static int preDrawCB(pfTraverser *trav, void *udata);
static int postDrawCB(pfTraverser *trav, void *udata);
private:
//****These are the functions that do the real work for the class call back
void preDraw();
void postDraw();
void setTravFuncs();
//***now in the definition of the class I setTravFunc for the "static" pre and post callbacks
//***and set the data to the "this" pointer which is the instance of the class
//***************************************************************
//***************************************************************
//****** Methods for traverser functions
//***************************************************************
//***************************************************************
void PFTK_Vehicle::setTravFuncs()
{
vehiclePos->setTravFuncs(PFTRAV_DRAW,preDrawCB,postDrawCB);
vehiclePos->setTravData(PFTRAV_DRAW,(void *)this);
}
//*** now extract which instance of the class we are using
//***and call the real pre and post callback functions
//***************************************************************
//***************************************************************
int PFTK_Vehicle::preDrawCB(pfTraverser *trav, void *udata)
{
PFTK_Vehicle *player = (PFTK_Vehicle *)udata;
player->preDraw();
return PFTRAV_CONT;
}
//***************************************************************
//***************************************************************
int PFTK_Vehicle::postDrawCB(pfTraverser *trav, void *udata)
{
PFTK_Vehicle *player = (PFTK_Vehicle *)udata;
player->postDraw();
return PFTRAV_CONT;
}
Pedro Lahon wrote:
> Hello,
>
> I've tried to set a callback function that has the same prototype that pfChanFuncType... but it's a function member of a class... I mean:
>
> The pfChanFuncType prototype is:
> void functionName(pfChannel *chan, void* data)
>
> and mine is:
> void className::functionName(pfChannel *chan, void* data)
>
> When I compile I get an error saying that is not a valid pfChanFuncType.
>
> Is it not possible to do what I want to do? Any trick to cheat the compiler or Performer?
>
> Thanks in advance,
>
> Ivan.
>
> http://webmail.wanadoo.es. Tu correo gratuito, rápido y en español
This archive was generated by hypermail 2b29 : Fri Aug 13 2004 - 07:16:49 PDT