It is difficult for me to call a pointer to a member function for an object that was different from void* . Example below:
class Test { public: Test(int pointTo) { if (pointTo == 1) function = &Test::Function1; else function = &Test::Function2; } static void CallIt(void* cStyle) { Test* t(static_cast<Test*>(cStyle)); (t->*function)();
What happens when an object is moved to void* and vice versa? Why can I no longer call a pointer to a member function?
EDIT:
Changing CallIt() as follows allows the program to compile, but I'm still wondering why the original did not work.
static void CallIt(void* cStyle) { Test* t(static_cast<Test*>(cStyle)); Test::ptrToMemberFunc pf(t->function); (t->*pf)(); }
c ++ pointer-to-member
Kerry
source share