How to define a member function pointer?


Here I define a pointer pMember pointing to CMyClass::MemberFunc and use it to call the function.

struct CMyClass
{
	int MemberFunc(char c)
	{
		return c;
	};
};
void test()
{
	CMyClass MyClass;
	int (CMyClass::*pMember)(char) = &CMyClass::MemberFunc;
	int iMember = (MyClass.*pMember)(2);
}
Advertisements
Comments are closed.
%d bloggers like this: