Boost logo

Boost Users :

From: Stephen Torri (storri_at_[hidden])
Date: 2006-06-30 12:28:43


I have a main file from my OpenGL program which contains global
variables and the functions that are used by OpenGL as callback
functions. For example:
        
        int a;
        float b;
        
        void display ()
        {
                .... display code calls ...
        }
        
        int main (int argc, char **argv)
        {
                    glutDisplayFunc( display );
        }
        
Now I thought I would put all the variables and functions into a class
and use that in the main. Here is where I am getting stuck on the use of
boost::function. I changed the code to look something like the
following:

        class MyMain {
                int a;
                float b;
        
                void display()
                {
                        ... display code calls ...
                }
        }
        
        int main (int argc, char **argv)
        {
                MyMain m_ref;
                boost::function<void()> disp_func = boost::bind ( &MyMain::display, &m_ref );
                glutDisplayFunc ( disp_func );
        }

What I am getting back from the g++ compiler is the following error message:

error: cannot convert `boost::function<void ()(), std::allocator<void> >' to `void (*)()' for argument `1' to `void glutDisplayFunc(void (*)())'

Any ideas where I am going wrong?

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