I want to call member-functions through member-function-pointers. The calling function is also a member.
class A;
typedef int (A::*memFun)();
class A
{
int P(){return 1;}
int Q(){return 2;}
int R(){return 3;}
int Z(memFun f1, memFun f2)
{
return f1() + f2(); //HERE
}
public:
int run();
};
int A::run()
{
return Z(P, Q);
}
int main()
{
A a;
cout << a.run() << endl;
}
I am not doing it correctly, and am getting error-
main.cpp:15:19: error: must use '.*' or '->*' to call pointer-to-member function in 'f1 (...)', e.g. '(... ->* f1) (...)'
return f1() + f2(); //HERE
Please show the correct way to do it.
EDIT - there is another error, which is solved by having-
return Z(&A::P, &A::Q);