Passing member function pointers to GLUT

How do I pass a member function pointer to glut?

For example, if I have:

class foo
void mouseMotion (int x, int y);

How would I pass mouseMotion to glutMouseMotionFunc();?

You cannot.
After all, in this code:
foo foobar;
GLUT has no knowledge of the foobar variable that owns the method you want to be called.

On the other hand you can use static method:

class foo {
static void mouseMotion (int x, int y);

glutMouseMotionFunc( foo::mouseMotion );

If required, you can store a static pointer to foobar in the foo class, and make a call to foobar->mouseMotion from foo::mouseMotion

What I used to do is have global C methods call member methods in global objects. I would write these adapters manually, which kind of sucked.

One option that might work for you (haven’t tried it though) is to use the mem_fun<>() STL function adapter in the <functional> library.