类名和函数名用大写字母开头的单词组合而成

类名和函数名用大写字母开头的单词组合而成。

例如: class Node; // 类名 class LeafNode; // 类名 void Draw(void); // 函数名 void SetValue(int value); // 函数名

 

 1 #include <iostream>
 2 
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std;
 5 //定义一个含有static数据成员的类
 6 class ex
 7 {
 8     static int num;      //static数据成员
 9 public:
10     ex() {num++;}
11     ~ex() {num--;}
12     static disp_count(void) //static成员函数
13     {
14         cout<<"The current instances count:";
15         cout<<num<<endl;
16     }
17 };
18 int ex::num=0;    //设置static数据成员的初值
19 //main()函数测试ex类
20 int main(int argc, char** argv) {
21        ex a;
22     a.disp_count();
23 
24     ex *p;
25     p=new ex;
26     p->disp_count();
27 
28     ex x[10];
29     ex::disp_count();   //直接用类作用域符引用静态成员函数
30 
31     delete p;
32     ex::disp_count();  //直接用类作用域符引用静态成员函数
33     return 0;
34 }

 

posted @ 2018-08-03 12:17  borter  阅读(888)  评论(0编辑  收藏  举报