?? 6_14.cpp
字號:
//6_14.cpp
#include <iostream>
using namespace std;
class Point //Point類聲明
{
public: //外部接口
Point(int xx=0, int yy=0) {X=xx;Y=yy;countP++;} //構(gòu)造函數(shù)
Point(Point &p); //拷貝構(gòu)造函數(shù)
int GetX() {return X;}
int GetY() {return Y;}
static int countP; //靜態(tài)數(shù)據(jù)成員引用性說明
private: //私有數(shù)據(jù)成員
int X,Y;
};
Point::Point(Point &p)
{
X=p.X;
Y=p.Y;
countP++;
}
int Point::countP=0; //靜態(tài)數(shù)據(jù)成員定義性說明
void main() //主函數(shù)實(shí)現(xiàn)
{
int *count=&Point::countP; //聲明一個(gè)int型指針,指向類的靜態(tài)成員
Point A(4,5); //聲明對象A
cout<<"Point A,"<<A.GetX()<<","<<A.GetY();
cout<<" Object id="<<*count<<endl; //直接通過指針訪問靜態(tài)數(shù)據(jù)成員
Point B(A); //聲明對象B
cout<<"Point B,"<<B.GetX()<<","<<B.GetY();
cout<<" Object id="<<*count<<endl; //直接通過指針訪問靜態(tài)數(shù)據(jù)成員
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -