如果问题太过琐碎,请见谅。
我有一个由多个映射组成的向量:
typedef map<char, int> edges;
typedef vector<edges> nodes;
nodes n;
现在假设我想推送一个玩具边缘。我尝试了不同的方法,最终成功的方式是:
edges e; //declare an edge
e['c'] = 1; //initialize it
n.push_back(e); //push it to the vector
如何在不声明变量或初始化的情况下,仅推送边缘('c'和2)的一对值?
类似于:
n.push_back(edges('c',2));
但编译器报错了。
error: no matching function for call to ‘std::map<char, int>::map(char, int)’