?? 6_13.cpp
字號(hào):
//6_13.cpp
#include <iostream>
using namespace std;
class Point //類(lèi)的聲明
{
public: //外部接口
Point(int xx=0, int yy=0) {X=xx;Y=yy;} //構(gòu)造函數(shù)
int GetX() {return X;} //內(nèi)聯(lián)函數(shù),返回X
int GetY() {return Y;} //內(nèi)聯(lián)函數(shù),返回Y
private: //私有數(shù)據(jù)
int X,Y;
};
void main() //主函數(shù)
{
Point A(4,5); //聲明對(duì)象A
Point *p1=&A; //聲明對(duì)象指針并初始化
int (Point::*p_GetX)()=Point::GetX; //聲明成員函數(shù)指針并初始化
cout<<(A.*p_GetX)()<<endl; //(1)使用成員函數(shù)指針訪(fǎng)問(wèn)成員函數(shù)
cout<<(p1->GetX)()<<endl; //(2)使用對(duì)象指針訪(fǎng)問(wèn)成員函數(shù)
cout<<A.GetX()<<endl; //(3)使用對(duì)象名訪(fǎng)問(wèn)成員函數(shù)
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -