cuziyq
asked on
C++ pointer to member function
I am sure I am just getting caught up in the syntactic ugliness of function pointers here, but can somebody help me out?
I am getting this compiler error on the following code:
error C2664: 'Derived::Derived(FxnPtr)' : cannot convert parameter 1 from 'void (__thiscall TestApp::* )(void)' to 'FxnPtr'
I am getting this compiler error on the following code:
error C2664: 'Derived::Derived(FxnPtr)'
#define TEST_API __declspec(dllexport)
//Base and Derived classes are exported from a DLL
class TEST_API Base
{
public:
Base() {}
virtual ~Base() {}
};
typedef void(Base::*FxnPtr)();
class TEST_API Derived :public Base
{
public:
Derived(FxnPtr fxn) {}
~Derived() {}
};
//The following code is in the EXE
#include "windows.h"
class TestApp :public Derived
{
public:
TestApp() :Derived(&TestApp::Func) {}
~TestApp() {}
void Func() {}
};
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
return 0;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Depending on your specific needs, there might be other ways to solve your problem. Are you needing to pass the address of an object member function to a Windows API fn (such as SetTimer) that needs a callback address?