Hello to all, i have wrote a self member function pointer.
I try to do callback to member function but the statement is not executed by the compiler. I try to debug and found nothing wrong.
this->theMFPtr[choice]; does not get executed by the compiler.Code:#ifndef SELF_MEMBER_FUNCTION_PTR_H #define SELF_MEMBER_FUNCTION_PTR_H #include <iostream> class myClass { private: typedef void (myClass::*MemberFunctionPtr)(); MemberFunctionPtr theMFPtr[4]; public: myClass() { theMFPtr[0] = &myClass::function1; theMFPtr[1] = &myClass::function2; theMFPtr[2] = &myClass::function3; theMFPtr[3] = &myClass::function4; } void function1() {std::cout << "function1";} void function2() {std::cout << "function2";}; void function3() {std::cout << "function3";}; void function4() {std::cout << "function4";}; void callBack(int choice) { this->theMFPtr[choice]; } }; #endif #include <iostream> #include "Class.h" using namespace std; int main() { myClass theObject; theObject.callBack(1); return 0; }
Please help.
Thanks.




Reply With Quote