メンバーポインタ

2121 ワード

#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()

}