类成员函数,如果是静态函数,其函数指针很好说,也很容易理解。但如果是非静态函数呢?像在Python里的函数方法,静态的成员函数,第一个参数是cls类,非静态的成员函数,第一个参数是self。而在C++中如何写咧,代码如下:
class A;
typedef void (A::*handler)(int);
class A
{
public:
    A() {
        n = 100;
        h = &A::output;
    }
    void output(int d) {
        cout << n + d << endl;
    }
    void output2(int d) {
        (this->*h)(d); //内部使用
    }
private:
    int n;
    handler h;
};
int main()
{
    A a;
    A *ap = &a;
    handler h = &A::output;
    (a.*h)(100);     //方式一
    (ap->*h)(100);   //方式二
    a.output2(100);
    return 0;
}