static关键字
http://hi.baidu.com/helfen/blog/item/d6d208dba1d1146ed0164e29.html // C++ static 类的静态成员函数 #include <iostream.h> class ok { int a; static int s;//声明静态数据成员 public: ok(int a); static void show();//声明静态成员函数 }; int ok::s=0;//定义并初始化静态数据成员 ok::ok(int a) { this->a=a; s+=a; //非静态成员函数可以访问静态数据成员 } void ok::show() //静态成员函数的实现 { //cout<<a<<endl; //错误代码,a是非静态数据成员 cout<<"s="<<s<<endl; } void main() { ok cat(2); cat.show(); ok dog(3); dog.show(); ok::show(); } /*------------------------------------------------------------ ○静态成员之间可以相互访问,如静态成员函数访问静态数据成员和静态成员函数; ○静态成员函数没有this指针。无法访问属于类对象的非静态数据成员和非静态成员函数,