hi,

>> Does anyone (anyone, that is, who's coded X11 applications) know how you
>> handle X11 callbacks to C++ object methods?
>> 
>> Thanks,

 TDR>  If you mean Xt (and possibly Motif) - the answer is "very carefully."

 TDR>  The Xt callbacks are C based, so you typically can't directly call a 
 TDR>  C++ method.

 TDR>  But, you can have an extern "C" block that declares the call back
 TDR>  function (the extern "C" basically keeps any name mangling from going on)
 TDR>  and then, in that function, invoke the method as appropriate.

 TDR>  I believe you do something like:

 TDR>       class myclass {
 TDR>   void mymethod(void * arg1) {
 TDR>           cout << "Ha! I got to the class" << '\n';
 TDR>   };
 TDR>       }

 TDR>       extern "C" {

 TDR>          void
 TDR>          callback_function(arg1)
 TDR>          void *arg1;
 TDR>          {
 TDR>     /* Call the method */
 TDR>      myclass::mymethod(arg1);
 TDR>          }

 TDR>       }

Looks good except one point -- mymethod should be static, i.e.

static void mymethod (...) {
  ...
}

 TDR> Then, you register "callback_function" as the Xt/Motif callback.

 TDR> I've at least "heard" of doing that kind of thing before...

-- 
/* Alexey Zelkin                       && [EMAIL PROTECTED]    */
/* Tavric National University          && [EMAIL PROTECTED]  */
/* http://www.ccssu.crimea.ua/~phantom && [EMAIL PROTECTED] */


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to