c++ - map 初始化 map

标签 c++ c++11 dictionary std stdmap

我正在尝试初始化 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/

相关文章:

c++ - 是否可以将大括号括起来的初始化程序作为宏参数传递?

c++ - 删除数组而不调用析构函数

python - 将数据从Python列表和字典写入CSV

c++ - 为什么我不能在 switch/case 中使用 unsigned short?

C++11:如何通过继承使用 std::mem_fn 和 std::bind

c++ - 使用模板将任何类型的参数传递给 c++ 中的函数

c++ - 在 OpenCV 中使用 MouseCallback 绘图

c++ - 销毁顺序和赋值

Python 强制 dict 条目为 utf-8

Python 处理字典、文件