【发布时间】:2014-05-05 14:15:30
【问题描述】:
我有以下代码:
#include <iostream>
#include <utility>
#include <map>
using namespace std;
int main()
{
map<int, map<string, int> > mapa;
// way A
mapa[10]["aaa"] = 20;
// way B -> Compilation Error
pair<int, pair<string, int> > par(10, make_pair("aaa", 20));
mapa.insert(par);
return 0;
}
我知道填充地图的“方式 A”是有效的。 我想使用“方式 B”,但它会引发编译错误: 错误:没有匹配函数调用‘std::map, int>::map(const std::pair, int>&)’
如何使用插入运算符填充嵌套地图。
Pd:我不使用 [] 运算符,因为它需要定义默认构造函数,因为我使用的是来自 Boost 的 time_period 对象,所以我没有。
【问题讨论】: