Re: C++ Draw Callback?

New Message Reply Date view Thread view Subject view Author view

Hansong Zhang (zhangh++at++cs.unc.edu)
Thu, 28 Nov 1996 10:37:46 -0500 (EST)


>
>
> > I'd like to have a C++ method as the callback function, set by
> > pfChannel->setTravFunc(). I've tried lots of different ways to
> > code this, but the compiler always seems to have trouble with
> > the function pointer (2nd argument) being an Object method.
>
> You can either write a simple function wrapper that uses a global variable
> to remember the object and call its member function, then use this wrapper
> as the callback; or, perhaps more elegantly, your callback should be
> defined as a static member function of the object, e.g.
>
> class MyClass {
> public:
> static void DrawChannel( pfChannel *chan, void *data );
> };
>
> void MyClass::DrawChannel( pfChannel *chan, void *data )
> {
> // your Draw call back code here
> }
>
> ....
>
> chan->setTravFunc( PFTRAV_DRAW, MyClass::DrawChannel );
> ....
>
>
> Martin.
>

The same thing can be done to non-static member functions, also.
But you need a explicit type conversion:

chan->setTravFunc( PFTRAV_DRAW, (pfChanFuncType)MyClass::DrawChannel );

You'll still get an warning about this conversion, but you could
ignore that...

Hansong

-------------------------------------------------------------
Hansong Zhang \ zhangh++at++cs.unc.edu
Walkthrough Group \ http://www.cs.unc.edu/~zhangh
Department of Computer Science \ (919)962-1835 (O)
UNC-Chapel Hill \ (919)914-3973 (H)

"I create abstract systems from pure information, Albert. I'm
a *programmer*... Quantum nonlocality is a bug." -- God
-------------------------------------------------------------
=======================================================================
List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/
            Submissions: info-performer++at++sgi.com
        Admin. requests: info-performer-request++at++sgi.com


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:54:02 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.