44(function pointer 2)

#include<iostream>
using namespace std;

class A
{
public:
    int x;
    int sayhello()
    {
        cout<<"hello world"<<endl;
    }
};

class B:public A
{

};

typedef int A::*int_pointer;
typedef int (A::*FP)();

int main()
{
    int A::*pointer1 = &A::x;
    int_pointer pointer2 = &A::x;
    A a;
    a.*pointer1 = 6;
    ++(a.*pointer2);
    cout << &a->*pointer1 << endl;

    B b;
    a.sayhello();
    int (A::*classAfunctionpointer1)();
    classAfunctionpointer1 = &A::sayhello;
    FP classAfunctionpointer2 = &A::sayhello;
    (a.*classAfunctionpointer1)();
    (a.*classAfunctionpointer2)();
    (&a->*classAfunctionpointer1)();
    (b.*classAfunctionpointer1)();

    return 0;
}

 

原文地址:https://www.cnblogs.com/acm-icpcer/p/6729278.html