C++中的静态数据成员和静态成员函数

来源:互联网 发布:安特数据 编辑:程序博客网 时间:2024/04/28 23:23
Code:
  1. #include<iostream>   
  2. #include<string.h>   
  3. using namespace std;   
  4. #define Min(x,y) x>y?y:x   
  5.   
  6. class Person   
  7. {   
  8. private:   
  9.     static int number;   
  10.     int a;   
  11. public:   
  12.     static int getnumber()   
  13.     {   
  14.         return number;   
  15.     }   
  16.     Person(int x = 0):a(x)   
  17.     {   
  18.         number++;          
  19.     }   
  20. };   
  21.   
  22. int Person::number = 0;   
  23.   
  24. int main()   
  25. {   
  26.     Person a;   
  27.     cout<<Person::getnumber()<<endl;   
  28.        
  29.        
  30.     return 0;      
  31. }  

 

原创粉丝点击