Link to home
Start Free TrialLog in
Avatar of cuziyq
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'
#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;
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?