?? p2-112.cpp
字號:
#include<iostream.h>
//定義一個含有static數據成員的類
class ex
{
static int num; //static數據成員
public:
ex() {num++;}
~ex() {num--;}
static disp_count(void) //static成員函數
{
cout<<"The current instances count:";
cout<<num<<endl;
}
};
int ex::num=0; //設置static數據成員的初值
//main()函數測試ex類
main()
{
ex a;
a.disp_count();
ex *p;
p=new ex;
p->disp_count();
ex x[10];
ex::disp_count(); //直接用類作用域符引用靜態成員函數
delete p;
ex::disp_count(); //直接用類作用域符引用靜態成員函數
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -