Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Endy

Function pointer conversion problem...

This topic is 5806 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m fairly new to C++ programming and have run into the following problem using Microsoft Visual C++. I am using the GLUT opengl library and trying to register a callback function. If I do it like this: void mainWindow1CallbackFunction(void); void main(int argc, char* argv[]) { blah blah blah glutDisplayFunc(mainWindow1CallbackFunction); blah blah blah } it works fine; however, if I try to put this in a class so: class foo { public: foo(); void mainWindowCallback(void); blah } void foo::foo() { blah blah blah glutDisplayFunc(this->mainWindow1CallbackFunction); blah blah blah } then windows complains about: : error C2664: ''glutDisplayFunc'' : cannot convert parameter 1 from ''void (void)'' to ''void (__cdecl *)(void)'' None of the functions with this name in scope match the target type C I''ve tried casting various ways but can''t get the compiler to be happy. I''d appreciate a suggestion on how to fix this. Regards, John

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by Endy
I''ve tried casting various ways but can''t get the compiler to be happy. I''d appreciate a suggestion on how to fix this.

Member function pointers cannot be cast to pointers to non-member functions, simply because there is no place in a non-member function pointer for "this". You will have to rethink your design to register either a non-member or a static member s the callback.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!