我有这个代码:
using namespace std;
struct nodeT;
struct arcT;
class Graph
{
public:
Graph(string xd);
void addnode(string name,float xval,float yval);
void addarc(string n1,string n2,float dist);
void printarcs();
private:
struct graphT
{
vector<nodeT *>nodes;
vector<arcT * > arcs;
map<string,nodeT * > nodemap;
};
struct nodeT{
string nodename;
float x,y;
vector<arcT * > arcs;
};
struct arcT{
nodeT * start;
nodeT * finish;
float distance;
};
void arcfinal(nodeT * a,nodeT * b, float len);
graphT * g;
//graphT *g=new graphT;
};
//#include "BST.cpp"
#endif
#include "Graph.h"
Graph::Graph(string xd)
{
g=new graphT;
}
void Graph::addnode(string name,float xval,float yval)
{
//if(!nodemap[name])
nodeT *t=new nodeT;
t->nodename=name;
t->x=xval;
t->y=yval;
g->nodes.push_back(t);
g->nodemap[name]=t;
}
void Graph::addarc(string n1,string n2,float dist)
{
nodeT * t1=g->nodemap[n1];
nodeT * t2=g->nodemap[n2];
arcfinal(t1,t2,dist);
arcfinal(t2,t1,dist);
}
void Graph::arcfinal(nodeT * a,nodeT * b, float len)
{
arcT * d=new arcT;
d->start=a;
d->finish=b;
d->distance=len;
g->arcs.push_back(d);
a->arcs.push_back(d);
}
void Graph::printarcs()
{
for(arcT * curr=g->arcs.begin();curr != g->arcs.end();++curr)
{
cout<<curr->start->nodename<<"-----"<<curr->finish->nodename<<"----"<<curr->distance<<endl;
}
}
//#endif
我收到了这个错误:
projects\graphsearch\graphsearch\graph.cpp(21) : 错误 C2664: 'std::vector<_Ty>::push_back' : 无法将参数 1 从 'Graph::nodeT *' 转换为 'nodeT *const &'.. ..
任何人都可以调试它吗?