Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::bind and Motif
From: Sven Bauhan (sven.bauhan_at_[hidden])
Date: 2012-05-03 04:55:42


> No, you don't have to make a signleton. The function XtAppAddTimeOut
> accepts "XtPointer client_data" argument, where you can pass "this".
> Then you get it back in the callback function, and type-cast it to its
> original type.
>
Ok this is another solution. But I don't like such pointer casts.
I have done it the following way:

class AnimationController {
private:
     static boost::optional<AnimationController&> cInstance;
public:
     static AnimationController& instance() {
         return cInstance.get();
     }
     AnimationController() {
         cInstance = *this;
     }
     static void timerCB() {
         instance().animate();
     }
private:
     void animate();
};

Just as praise for boost::optional :-)
Sven


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