static 用法总结 类方法修饰
这个很全:
http://www.cnblogs.com/BeyondAnyTime/archive/2012/06/08/2542315.html
在面向对象这块,主要作为类方法的前缀。
.h中
class Dog{ public: Dog(); ~Dog(); void setAge(int a); //普通成员方法 int getAge(); //类方法 static void show(); private: int age; int sex; };
.m中
Dog::Dog(){ cout<<"dog new"<<endl; } Dog::~Dog(){ cout<<"dog delet"<<endl; } void Dog::setAge(int a){ age = a; } int Dog::getAge(){ return age; } void Dog::show() { cout<<"dog is our friend"<<endl; }
调用
Dog *xiaohei = new Dog(); //对象方法 xiaohei->setAge(10); int age = xiaohei->getAge(); cout<<age<<endl; //类方法 Dog::show();