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