initialize a static const value outside of Constructor only for integral types

来源:互联网 发布:mac地址长度为多少位 编辑:程序博客网 时间:2024/05/21 10:22
class A{private: static const int a = 4; // valid static const std::string t ; // can't be initialized here ... ...};// in a cpp file where the static variable will exist const std::string A::t = "this way it works";


Also, note that this rule have been removed in C++11, now (with a compiler providing the feature) you can initialize what you want directly in the class member declaration.

原创粉丝点击