我正在尝试使用地图矢量创建图形。我实际上是在查看书中的代码并尝试将其输入到 Visual Studio 2012 中,这样我就可以弄乱图表了。但由于某种原因,它不允许我在向量中添加一对。下面的代码
创建向量
//vector that holds a map of all adjacent vertices
vector<map<int, int> > adjList;
图类的构造函数
Graph::Graph(int n){
map<int, int> element;
adjList.assign(n, element);
}
将项目添加到向量中
int v1 = e.v1;
int v2 = e.v2;
int weight = e.weight;
//add the first vertix the edge connects to intto the adjList
adjList.insert(make_pair(v1, weight));
//add the second vertix the edge connects to into the adjList
adjList.insert(make_pair(v2, weight));
尝试编译时我从 Visual Studios 2012 得到的错误
Error 1 error C2661: 'std::vector<_Ty>::insert' : no overloaded function takes 1 arguments c:\users\elliot\documents\visual studio 2012\projects\graph\graph.cpp 25 1 Project1
Error 2 error C2661: 'std::vector<_Ty>::insert' : no overloaded function takes 1 arguments c:\users\elliot\documents\visual studio 2012\projects\graph\graph.cpp 27 1 Project1