本文介绍了调试地图插入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在将条目插入到地图时遇到问题.
I'm having an issue with inserting an entry into a Map.
#include <stdio.h>
#include <vector>
#include <stack>
#include <map>
using namespace std;
class Nodo
{
public:
vector<Nodo> Relaciones;
int Valor;
bool Visitado;
Nodo(int V)
{
Valor = V;
Visitado = false;
}
};
class Grafo
{
public:
Nodo *Raiz;
map<int, Nodo> Nodos;
Grafo(int V)
{
Raiz = new Nodo(V);
//Getting http://msdn.microsoft.com/en-us/library/s5b150wd(v=VS.100).aspx here
Nodos.insert(pair<int, Nodo>(V, Raiz));
}
};
推荐答案
您的类型不匹配.您正在将Nodo*
传递给pair
构造函数,而它需要一个Nodo
对象.
You have a type mismatch. You're passing a Nodo*
into the pair
constructor while it expects a Nodo
object.
您声明:
Nodo *Raiz;
,然后您尝试致电:
pair<int, Nodo>(V, Raiz)
,它需要一个int
和一个Nodo
.但是您通过了int
和Nodo*
.
which expects an int
and a Nodo
. But you passed it int
and Nodo*
.
您可能想要的是这样:
class Grafo
{
public:
Nodo *Raiz;
map<int, Nodo*> Nodos; // change to pointer
Grafo(int V)
{
Raiz = new Nodo(V);
//Getting http://msdn.microsoft.com/en-us/library/s5b150wd(v=VS.100).aspx here
Nodos.insert(pair<int, Nodo*>(V, Raiz)); // change to pointer
}
};
这篇关于调试地图插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!