Archived

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

Passing a class function to a function pointer

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

Share on other sites
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.

• Forum Statistics

• Total Topics
628364
• Total Posts
2982269

• 10
• 9
• 13
• 24
• 11