我为冗长的代码道歉,但我一直在努力发现错误并且真的无法找到它。当我尝试运行它时出错。
void setADist(vector<Facility> &vFac, vector<Client> &vClient, vector<Edge> &vEdge, vector<Node> &vNode){
...
vector<Edge> temp(vEdge);
float *distance;
...
temp.push_back(Edge(101, 101, facEndNode, py(vFac[i].getLongitude(), x, vFac[i].getLatitude(), y)));
Graphs *g1 = new Graphs();
struct Graph* graph1 = g1->createGraph(temp.size());
for (int k = 0; k < temp.size(); k++){
//g1->addEdge(graph1, temp[k].getStartNode(), temp[k].getEndNode(), temp[k].getDist()); //THIS LINE CAUSES THE EXCEPTION
}
//g1->printGraph(graph1);
//distance = g1->dijkstra(graph1, vFac[i].getNodeID());
}
}
}
}
当我调用方法时,注释行会导致异常。
我尝试在main()中单独运行下面的代码,并且没有发现任何异常,因此它与Graphs类无关。
Graphs *g = new Graphs();
struct Graph* graph = g->createGraph(vEdge.size());
for (int i = 0; i < vEdge.size(); i++){
g->addEdge(graph, vEdge[i].getStartNode(), vEdge[i].getEndNode(), vEdge[i].getDist());
}
//g->printGraph(graph);
如果有人能为我提供解决方案,我真的很感激。