struct B
{
void (B::*pf)(int, int); // data member
B () : pf(&B::foo) {}
void foo (int i, int j) { cout<<"foo(int, int)\n"; } // target method
};
int main ()
{
B obj;
// how to call foo() using obj.pf ?
}
In above test code, pf
is a data member of B
. What's the grammar rule to invoke it ? It should be straight forward, but I am not getting a proper match. e.g. If I try obj.*pf(0,0);
then I get:
error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘pf (...)’, e.g. ‘(... ->* pf) (...)’
"How to call class member using function pointer?"
, While I am asking"<...same...>, when the function pointer itself is a class member also."
. Notice that answers to both the questions are different. – Magyar(obj.*ptr)
, just that hereptr == (obj.ptr)
. But well, since you disagree I'll retract ;-) – Kenny