成员指针

#include<iostream>
#include<string>
using namespace std;
class  boy
{
       public:
       int a;
       int b;
       boy(int a,int b):a(a),b(b){}
       void get(){cout<<a<<" "<<b<<endl;}
};
int main()
{
       boy a(2,3);
       boy *mm=&a;
       a.get();
       int boy::*p=&boy::a;//类型名 类名+作用与域说明符+*变量    
       //注意右边一定是 类+::
       void (boy::*f)()=&boy::get;
       cout<<a.*p<<endl;//访问方式
       (a.*f)();//访问方式,一定要加括号
       (mm->*f)();
       //f()
}
原文地址:https://www.cnblogs.com/cs1003/p/2817188.html