【发布时间】:2010-04-30 04:28:40
【问题描述】:
我用 C++ 完成我的家庭作业,但我在多重定义方面遇到了一些问题。
我的图表类;
class Graph{
private:
string name; //Graph name
fstream* graphFile; //Graph's file
protected:
string opBuf; //Operations buffer
int containsNode(string); //Query if a node is present
Node* nodes; //Nodes in the graph
int nofNodes; //Number of nodes in the graph
public:
static int nOfGraphs; //Number of graphs produced
Graph(); //Constructors and destructor
Graph(int);
Graph(string);
Graph(const Graph &);
~Graph();
string getGraphName(); //Get graph name
bool addNode(string); //add a node to the graph
bool deleteNode(string); //delete a node from the graph
bool addEdge(string,string); //add an edge to the graph
bool deleteEdge(string,string); //delete an edge from the graph
void intersect(const Graph&); //intersect the graph with the <par>
void unite(const Graph&); //intersect the graph with the <par>
string toString(); //get string representation of the graph
void acceptTraverse(BreadthFirst*);
void acceptTraverse(DepthFirst *);
};
还有我的遍历类;
class Traversal {
public:
string *visitedNodes;
virtual string traverse (const Graph & );
};
class BreadthFirst : public Traversal {
public :
BreadthFirst();
string traverse();
};
class DepthFirst : public Traversal {
public :
DepthFirst();
string traverse();
};
我的问题是在遍历类中,我需要同时声明Graph类,在Graph类中我需要声明遍历类。
我对 declerations 有很大的问题 :) 你能帮帮我吗?
【问题讨论】:
-
我只是想说,你真的不需要这样评论代码。每一行代码都应该是不言自明的,我认为确实是你的情况,所以你真的不需要复制信息。您应该评论的事情是决定,例如您使用了基于节点对象的图形实现(而不是基于边缘对象或边缘矩阵)。