0
我需要一个类来从字符串到指向一个函数的const std::map
。我怎么能初始化这个地图没有添加元素是这样的:用C++初始化一个映射
string func1(string a){
return a;
}
string func2(string x){
return "This is a random string";
}
//In class declaration:
const map<string,string(*)(string)> a;
//Where should this go? Any other, probably better method to initialize this map?
a["GET"] = &func1;
a["SET"] = &func2;
编辑:
我上预C++ 11
的可能的复制[会是什么一个std ::地图扩展初始化列表是什么样子?](http://stackoverflow.com/questions/3250123/what-would-a-stdmap- extended-initializer-list-look-like) – IInspectable
@IInspectable对不起,我没有提到我没有使用C++ 1y。 –
你只需要C++ 11。 – juanchopanza