成员函数指针的初始化
我照着一本书的例子写了个程序编译出错:#include<iostream>
using namespace std;
class Point{
public:
Point(int xx=0,int yy=0){X=xx;Y=yy;}
int GetX() {return X;}
int GetY() {return Y;}
private:
int X,Y;
};
int main()
{Point A(4,5);
Point *pp=&A;
int (Point::*p_GetX)()=Point::GetX; //声明成员函数指针并初始化
cout<<A.GetX()<<"\t";
cout<<(A.*p_GetX()<<"\t";
cout<<pp->GetX()<<"\t";
cout<<(pp->*p_GetX)()<<endl;
getch();
}
注释的那一行有错:
14 E:\小软件\C++\pp.cpp invalid use of non-static member function `int Point::GetX()'
请高手指教,谢谢!