【发布时间】:2017-09-22 13:57:58
【问题描述】:
我正在尝试使用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?
-
你是对的:/
-
如果下面的答案让您满意,请点击答案分数右侧的绿色复选标记。