【发布时间】:2016-04-13 16:37:39
【问题描述】:
所以我试图打电话给我的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”
#includes“Vertex.hpp”? -
不是这样的。所有
Edge.hpp包括<stdio.h> -
您试图在
Graph的成员函数中使用Vertex的成员变量?它们之间是什么关系? -
Graph.hpp包括Vertex.hpp和Vertex.hpp包括Edge.hpp。