Passing a class function to a function pointer

Started by
0 comments, last by Chocoboko 20 years, 9 months ago
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.
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.

This topic is closed to new replies.

Advertisement