1.使用static类的优点: (1)避免与其他类的成员或者全局变量冲突 (2)可以封装 (3)阅读性好 2.static 数据成员独立于该类的任意对象而存在 static数据成员的类型可以是该成员所属的类类型.非static成员被限定声明为其自身类对象的指针或引用. class Bar{ public: // private: static Bar mem1; //ok Bar *mem2;//ok Bar &mem3;//ok Bar mem4;/
const定义的常量在超出其作用域之后其空间会被释放,而static定义的静态常量在函数执行后不会释放其存储空间. static表示的是静态的.类的静态成员函数.静态成员变量是和类相关的,而不是和类的具体对象相关的.即使没有具体对象,也能调用类的静态成员函数和成员变量.一般类的静态函数几乎就是一个全局函数,只不过它的作用域限于包含它的文件中. 在C++中,static静态成员变量不能在类的内部初始化.在类的内部只是声明,定义必须在类定义体的外部,通常在类的实现文件中初始化,如:double Ac
在我的文件里有这class NFDuration, NFDuration.h里是这样的: // A Duration represents the elapsed time between two instants // as an int64 nanosecond count. The representation limits the // largest representable duration to approximately 290 years. class NFDuration