我正在尝试实例化一组这样的字符串:
class POI {
public:
...
static const std::set<std::string> TYPES { "restaurant", "education", "financial", "health", "culture", "other" };
...
}
现在,当我这样做时,我得到了这些错误(都在这一行):
error: field initializer is not constant
static const std::set<std::string> TYPES { "restaurant", "education", "financial", "health", "culture", "other" };
error: in-class initialization of static data member 'const std::set<std::basic_string<char> > POI::TYPES' of non-literal type
error: non-constant in-class initialization invalid for static member 'POI::TYPES'
error: (an out of class initialization is required)
error: 'POI::TYPES' cannot be initialized by a non-constant expression when being declared
如果我假设集合中的字符串不被视为 const,这对我来说是有意义的。这真的是这里的问题吗?不幸的是,我找不到将初始化程序中的这些字符串声明为 const 的方法。这可能吗?