我试图用boost::assign::list_of()
在类中声明一个静态集合。在使用boost :: assign :: list_of时声明不能用非常量表达式初始化
MyClass.h
class MyClass
{
public:
static std::set<std::string> & formats_set();
private:
static const std::set<std::string> formats_;
}
MyClass.cpp
const std::set<std::string> MyClass::formats_ = boost::assign::list_of(
"Format1"
,"Format2"
,"Format3");
但是 - 当我尝试编译我收到错误 ‘MyClass::formats_’ cannot be initialized by a non-constant expression when being declared
有什么办法来解决这个问题? 谢谢!
我想你一定会使用C++ 98? – YSC
你是对的:/ – canadiadude
如果下面的答案满足你,请点击答案评分正好的绿色选中标记。 – YSC