0
というlist
のEdge*
を呼び出しようとしています。私は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