0
所以我想打電話給我的list
Edge*
s叫做edgelist
。我有一個graph.cpp
下面應該顯示該圖的鄰接列表。列表沒有在範圍內聲明
#include <sstream>
#include <fstream>
#include <iostream>
#include <string>
#include <list>
#include "Graph.hpp"
Graph::Graph(){}
void Graph::displayGraph(){
for(int i = 0; i < vertices[vertices.size()-1].label; i++){
cout << vertices[i].label << ": ";
for(int j = 0; j <= edgeList.size(); j++){
if(edgeList[j].start==i){
cout << edgeList[j].end;
}
}
}
}
Graph.hpp
包括Vertex.hpp
其下方。
#ifndef Vertex_hpp
#define Vertex_hpp
#include <stdio.h>
#include <list>
#include <string>
#include <vector>
#include "Edge.hpp"
using namespace std;
class Vertex {
public:
// the label of this vertex
int label;
// using a linked-list to manage its edges which offers O(c) insertion
list<Edge*> edgeList;
// init your vertex here
Vertex(int label);
// connect this vertex to a specific vertex (adding edge)
void connectTo(int end);
};
#endif /* Vertex_hpp */
然而,當我運行我的代碼時,我得到一個錯誤,說edgeList is not declared in this scope
。
難道是「Edge.hpp」'#include's「Vertex.hpp」? – nwp
不是這樣。所有'Edge.hpp'包括'' –
你想在'Graph'的成員函數中使用'Vertex'的成員變量?他們之間有什麼關係? – songyuanyao