• Advertisement

Archived

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

Passing a class function to a function pointer

This topic is 5345 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

Is it possible to pass a pointer of a class function to a function pointer outside the class. I''ll explain what I am trying to do: extern void (*ptrloop)(void); void MENUSYS::Open(){ ptrloop=(void(*)()) &MENUSYS::Loop; } void MENUSYS::Loop(){ // Code goes here } When I try to compile this code, I get an error saying "converting from `void (MENUSYS::*)()'' to `void (*)()''". Is it possible to pass the address of a class function to a variable outside the class? Thank you.

Share this post


Link to post
Share on other sites
Advertisement
As you know, when calling a member function of a class, that function also needs to have reference to the object that called it (through the this pointer). You can''t call the function "straight" because you then strip the context (which is the object that called it), and it won''t allow you to make the conversion.

Share this post


Link to post
Share on other sites

  • Advertisement