|
Boost Users : |
Subject: Re: [Boost-users] boost::bind and Motif
From: Igor R (boost.lists_at_[hidden])
Date: 2012-05-02 09:14:57
> I just tried to use boost::bind to create a function pointer from an object
> method to define it as a Motif callback function:
>
> class AnimationController {
> public:
> Â Â void timerCB( XtPointer, XtIntervalId* );
> Â Â void startTimer() {
> Â Â Â Â this->mTimeout = XtAppAddTimeOut( this->mAppContext,
> ANIMATION_TIMESTEP,
> Â Â Â Â Â Â Â Â boost::bind( &AnimationController::timerCB, this ), NULL );
> Â Â }
> Â Â ...
> };
>
> For the definition of the Motif function:
> XtIntervalId XtAppAddTimeOut(
>   XtAppContext   /* app_context */,
>   unsigned long   /* interval */,
> Â Â XtTimerCallbackProc /* proc */,
>   XtPointer     /* closure */
> );
>
> with
>
> typedef void (*XtTimerCallbackProc)(
>   XtPointer     /* closure */,
> Â Â XtIntervalId* Â Â /* id */
> );
>
> But I get the following error:
>
> ../AnimationController.cpp: In member function 'void
> geo::AnimationController::startTimer()':
> ../AnimationController.cpp:193: error: cannot convert
> 'boost::_bi::bind_t<void (&)(void*, XtIntervalId*), boost::_mfi::dm<void
> ()(void*, XtIntervalId*), geo::AnimationController>,
> boost::_bi::list1<boost::_bi::value<geo::AnimationController*> > >' to 'void
> (*)(void*, XtIntervalId*)' for argument '3' to 'XtIntervalId
> XtAppAddTimeOut(_XtAppStruct*, long unsigned int, void (*)(void*,
> XtIntervalId*), void*)'
Bind creates a function object, while XtAppAddTimeOut expects a
function pointer, as you mentioned.
You can define a static member function that matches
XtTimerCallbackProc signature, and pass it without bind.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net