我試圖用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