我有這樣的代碼:圖h文件和cpp文件即時得到許多錯誤
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) : error C2664: 'std::vector<_Ty>::push_back' : cannot convert parameter 1 from 'Graph::nodeT *' to 'nodeT *const &'....
誰能請調試呢?
如果代碼不編譯,你不能調試它。 – leppie
它編譯....即時通訊錯誤提到標題 – beckham556
這是一個編譯器錯誤,所以我看不出代碼如何編譯。 – leppie