【转载】在 C++ 中 初始化 静态 static 常量 const 成员
搬家中。。。。。。。。。请关注 nuihq.com
转载自:http://www.cppblog.com/leetaolion/archive/2009/01/10/71651.html
/****************在头文件中********************/class MyTestClass{public: MyTestClass();public: const int m_ciInt; const String m_csStr; static int m_siInt; static String m_ssStr; const static int m_csiInt; const static String m_cssStr;};/******************在实现文件中********************/int MyTestClass::m_siInt = 1; // static成员变量,在外部定义String MyTestClass::m_ssStr = "MyStr"; // static成员变量,在外部定义const int MyTestClass::m_csiInt = 1; // const static/static const成员变量,在外部定义const String MyTestClass::m_cssStr = "MyStr"; // const static/static const成员变量,在外部定义MyTestClass : m_ciInt(1), m_csStr("MyStr"){} // const成员变量,在ctor参数列表中初始化