static const member variable initialization
问题 Looks like I can init a POD static const member, but not other types: struct C { static const int a = 42; // OK static const string b = "hi"; // compile error }; Why? 回答1: The syntax initializer in the class definition is only allowed with integral and enum types. For std::string , it must be defined outside the class definition and initialized there. struct C { static const int a = 42; static const string b; }; const string C::b = "hi"; // in one of the .cpp files static members must be