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 ?
}
在上面的测试代码中,pf
是B
. 调用它的语法规则是什么?它应该是直截了当的,但我没有得到一个合适的匹配。例如,如果我尝试obj.*pf(0,0);
,那么我会得到:
error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘pf (...)’, e.g. ‘(... ->* pf) (...)’