Boost logo

Boost Users :

From: Stephen Torri (storri_at_[hidden])
Date: 2006-06-30 21:26:53


On Fri, 2006-06-30 at 14:40 -0400, Douglas Gregor wrote:
> On Jun 30, 2006, at 12:28 PM, Stephen Torri wrote:
> > boost::function<void()> disp_func = boost::bind
> > ( &MyMain::display, &m_ref );
> > glutDisplayFunc ( disp_func );
>
> Unfortunately, disp_func needs to be a function pointer. I wrote up a
> short article on the Wiki about using boost::function with C
> libraries. It may help you solve this problem:
>
> http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?
> Generalizing_C-Style_Callbacks
>
> Doug

Given your example I would need to create a class something like the
following:

        class A {
        private:
                typedef boost::function<void()> generic_opegnl_callback;
        
        public:
                void init()
                {
                        m_display_callback = boost::bind ( &display_impl, this );
                }
        
                void display_impl (void)
                {
                        ... display code ...
                }
        
                void display (void)
                {
                        m_display_callback();
                }
        
        private:
                generic_opengl_callback m_display_callback;
        };

Is this right?

Stephen


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