[GLUT] Pointers to class methods

This is a discussion on [GLUT] Pointers to class methods within the C++ Programming forums, part of the General Programming Boards category; I've created a little class which basically wraps up a little demo type thing I've written while following various GLUT ...

[GLUT] Pointers to class methods

I've created a little class which basically wraps up a little demo type thing I've written while following various GLUT tutorials and I need to make the calls to the "glutXFunc" (eg. glutDisplayFunc) but I'm stumped on how to give it a class method as a parameter.

c:\Documents and Settings\lee\Desktop\glutProj\glutProj.cpp(283) : error C2664: 'glutDisplayFunc' : cannot convert parameter 1 from 'void (__thiscall engineDemo::* )(void)' to 'void (__cdecl *)(void)'
There is no context in which this conversion is possible

It sort of worked. There were probs except I've had to make everything in the class static and the linker threw up unresolved externals because I forgot to type static in front of all the definitions, but when I did that I now get these:

Code:

------ Build started: Project: glutProj, Configuration: Debug Win32 ------
Compiling...
glutProj.cpp
c:\Documents and Settings\lee\Desktop\glutProj\glutProj.cpp(98) : error C2724: 'engineDemo::renderString' : 'static' should not be used on member functions defined at file scope
c:\Documents and Settings\lee\Desktop\glutProj\glutProj.cpp(107) : error C2724: 'engineDemo::playSound' : 'static' should not be used on member functions defined at file scope
c:\Documents and Settings\lee\Desktop\glutProj\glutProj.cpp(118) : error C2724: 'engineDemo::setOrthoProjection' : 'static' should not be used on member functions defined at file scope
c:\Documents and Settings\lee\Desktop\glutProj\glutProj.cpp(143) : error C2724: 'engineDemo::resetPerspectiveProjection' : 'static' should not be used on member functions defined at file scope
c:\Documents and Settings\lee\Desktop\glutProj\glutProj.cpp(151) : error C2724: 'engineDemo::render' : 'static' should not be used on member functions defined at file scope
c:\Documents and Settings\lee\Desktop\glutProj\glutProj.cpp(188) : error C2724: 'engineDemo::reshape' : 'static' should not be used on member functions defined at file scope
c:\Documents and Settings\lee\Desktop\glutProj\glutProj.cpp(208) : error C2724: 'engineDemo::normalKeys' : 'static' should not be used on member functions defined at file scope
c:\Documents and Settings\lee\Desktop\glutProj\glutProj.cpp(221) : error C2724: 'engineDemo::specialKeys' : 'static' should not be used on member functions defined at file scope
c:\Documents and Settings\lee\Desktop\glutProj\glutProj.cpp(243) : error C2724: 'engineDemo::mousePress' : 'static' should not be used on member functions defined at file scope
c:\Documents and Settings\lee\Desktop\glutProj\glutProj.cpp(265) : error C2724: 'engineDemo::mousePassiveMotion' : 'static' should not be used on member functions defined at file scope
Build Time 0:00
Build log was saved at "file://c:\Documents and Settings\lee\Desktop\glutProj\Debug\BuildLog.htm"
glutProj - 10 error(s), 0 warning(s)
---------------------- Done ----------------------
Build: 0 succeeded, 1 failed, 0 skipped

I've never had these before.
Oh yeah I don't understand how making them static 'makes it work'?

float engineDemo::m_angle;
float engineDemo::m_Red = 10; //you can initialize them as well

Still, it seems bad design to me to have a class full of static members. Maybe (and take what I say with a grain of salt because I'm no design expert) you want to use the singleton design pattern instead. In that case, you could have a single static instance of the class as a member, which would be used to access the data