Get the address of a member function
Hi
I have a static structure with a member int (*repfn)(int state, const char * reply,int tout) – a function pointer.
I want to initialise the pointer within my dialog constructor to point to a member function of my dialog class.
Like this:
Code:
CEnterDiagnostics::CEnterDiagnostics() : CPropertyPage(CEnterDiagnostics::IDD)
{
//{{AFX_DATA_INIT(CEnterDiagnostics)
//}}AFX_DATA_INIT
StateMachine[0].repfn = OpenReply;
}
Where OpenReply is a member of my class CEnterDiagnostics and declared as
int OpenReply(int state, const char *pReply,int tout);
But it doesn’t work I get a compiler error
C2440: '=' : cannot convert from 'int (__thiscall CEnterDiagnostics::*)(int,const char *,int)' to 'int (__cdecl *)(int,const char *,int)'
Is there a way to do this?
Thanks
Alec
noboost - just C++ (in case you#re looking for...)
To declare a pointer to a member function:
struct cfoo {
int bar(int x);
};
int (cfoo::*pFooBar)(int) = cfoo::bar;
// to call, you need an actual instance -
foo.*pFooBar(17);
pFoo->*pFooBar(42);
of course, functors are much more expressive and powerful... ;-)