我正在尝试初始化 map 的 map ,但我不确定自己犯了什么错误。下面是示例代码。
static std::map<std::string, std::map<std::string,std::string>> _ScalingMapVolume ={
{"AA",{"busy_timeout","test"}},
{"BB",{"cache_size","10000"}}
};
我得到的错误是;
error: no match for call to ‘(std::_Select1st<std::pair<const std::basic_string<char>, std::basic_string<char> > >) (const char&)’
最佳答案
{"busy_timeout","test"}
不是一个映射的值,而是一对。您需要 {{"busy_timeout","test"}}
。
您的代码应如下所示:
static std::map<std::string, std::map<std::string, std::string>> _ScalingMapVolume = {
{"AA", {{"busy_timeout", "test"}}},
{"BB", {{"cache_size", "10000"}}}
};
关于c++ - map 初始化 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23130407/