class Foo {
public:
Foo() { do_something = &Foo::func_x; }
int (Foo::*do_something)(int); // function pointer to class member function
void setFunc(bool e) { do_something = e ? &Foo::func_x : &Foo::func_y; }
private:
int func_x(int m) { return m *= 5; }
int func_y(int n) { return n *= 6; }
};
int
main()
{
Foo f;
f.setFunc(false);
return (f.*do_something)(5); // <- Not ok. Compile error.
}
어떻게 작동합니까?비 정적 멤버 함수에 대한 C++ 함수 포인터 (클래스 멤버)
'func_x' 및'func_y' 정적 함수는 그와 같이 표시되지 않습니까? –