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) (...)’