我在C++中爲我的作業工作,並且在乘法定義方面存在一些問題。與OOP類定義問題
我的圖課;
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類中,圖類,我需要遍歷類來聲明。
我遇到了很多問題:)請幫助我嗎?
我只想說,你真的不需要這樣評論代碼。每一行代碼都應該是不言自明的,我認爲它確實適合您的情況,所以您實際上不需要複製這些信息。您應該評論的內容是決定,例如您使用基於節點對象的圖形實現(而不是基於邊緣對象或邊緣矩陣)。 – 2010-04-30 09:12:07