Fucntion pointer question!
-
i declare a function pointer like this: void (*PTestFunc)(CString& str); and two classes: class CTest { ... void Test() { m_pTestFunc(CString("fdsaf")); } void SetFuncPointer(void* pointer) { m_pTestFunc = pointer; } PTestFunc m_pTestFunc; ... } class CMyClass { ... CString m_strCaption; void MyTest(CString& str); void Init(CTest& test); ... } CMyClass::MyTest(CString& str) { m_strCaption = str; } void CMyClass::Init(CTest& test) { test.SetFuncPointer((void*)MyTest); //error c2440 } ////////////////////////////// if i add "static" before MyTest, it is right; but u see i need this pointer in my class, i can't set MyTest static. so how to solve this problem? does c++ define the class member function pointer? :confused: c++ : my dream
-
i declare a function pointer like this: void (*PTestFunc)(CString& str); and two classes: class CTest { ... void Test() { m_pTestFunc(CString("fdsaf")); } void SetFuncPointer(void* pointer) { m_pTestFunc = pointer; } PTestFunc m_pTestFunc; ... } class CMyClass { ... CString m_strCaption; void MyTest(CString& str); void Init(CTest& test); ... } CMyClass::MyTest(CString& str) { m_strCaption = str; } void CMyClass::Init(CTest& test) { test.SetFuncPointer((void*)MyTest); //error c2440 } ////////////////////////////// if i add "static" before MyTest, it is right; but u see i need this pointer in my class, i can't set MyTest static. so how to solve this problem? does c++ define the class member function pointer? :confused: c++ : my dream
Non-static methods have 'this' as the first parameter. I just added a FAQ on this to the VC Forum FAQ, so check that out. :) --Mike-- It's hammer time! My really out-of-date homepage Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan and Jamie Salé.
-
i declare a function pointer like this: void (*PTestFunc)(CString& str); and two classes: class CTest { ... void Test() { m_pTestFunc(CString("fdsaf")); } void SetFuncPointer(void* pointer) { m_pTestFunc = pointer; } PTestFunc m_pTestFunc; ... } class CMyClass { ... CString m_strCaption; void MyTest(CString& str); void Init(CTest& test); ... } CMyClass::MyTest(CString& str) { m_strCaption = str; } void CMyClass::Init(CTest& test) { test.SetFuncPointer((void*)MyTest); //error c2440 } ////////////////////////////// if i add "static" before MyTest, it is right; but u see i need this pointer in my class, i can't set MyTest static. so how to solve this problem? does c++ define the class member function pointer? :confused: c++ : my dream
Not sure if this will solve your problem http://www.codetools.com/script/comments/forums.asp?forumid=1647&app=50&fr=251#xx142181xx Todd Smith CPUA 0x007 ... shaken not stirred