6-13

3284 ワード

 1 #include<iostream>
 2 
 3 using namespace std;
 4 class Point
 5 {
 6 public:
 7     Point(int x=0,int y=0):x(x),y(y){}
 8     int getX() const {return x;}
 9     int getY() const {return y;}
10 private:
11     int x,y;
12 };
13 int main()
14 {
15     Point a(4,5);
16     Point * p1=&a;
17 
18     int (Point::*funcPtr)() const=&Point::getX;
19 
20     cout<<(a.*funcPtr)()<<endl;
21     cout<<(p1->*funcPtr)()<<endl;
22     cout<<a.getX()<<endl;
23     cout<<p1->getX()<<endl;
24 
25     return 0;
26 }