【发布时间】:2019-05-07 00:38:45
【问题描述】:
对不起,如果这个问题很琐碎。
我有一个地图向量:
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)’
【问题讨论】:
-
哪个 C++ 标准? C++11?
-
是的,但如果解决方案与其他标准不同,如果您也能提供差异,我将不胜感激,谢谢
标签: c++ c++11 vector stdvector stdmap