OOP类定义的问题 我在C++中做作业,我在乘法定义上有一些问题。
我的图形课OOP类定义的问题 我在C++中做作业,我在乘法定义上有一些问题。,c++,oop,class,C++,Oop,Class,我的图形课 class Graph{ private: string name; //Graph name fstream* graphFile; //Graph's file protected: string opBuf; //Operations buffer int 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 *);
};
我的问题是在遍历类中,我需要同时声明图类,在图类中我需要遍历类来声明
我有很大的问题:)你能帮我一下吗?不,你不需要类的定义。您只需要向编译器提示
Graph
和Traversal
是类。所以使用像类广度优先在图的定义中,
(即类图{..}的正上方)。同样使用类图代码>在遍历类定义之前。在其中一个类之前预先声明您的类,例如,在遍历头文件中,在遍历类之前,您需要一条语句
类图
然后它会知道某个点上会存在一个Graph类,向前声明会有所帮助,看看仅仅做AcceptTraversal(Traversal*),这可能会对您有所帮助。如果我真的理解了,我尝试了这个
在图形类中,在添加图形类偏差之前
class BreadthFirst;
class DepthFirst;
在traversal.cpp文件中,我使用了这个
#include "Graph.h"
#include "Traversal.h"
有了这个,很多问题都解决了,但是现在
错误8错误LNK2001:
未解析的外部符号“公共:
虚拟类
std::基本_字符串,类
std::分配器>\uuu此调用
遍历::遍历(类图常量)
&)"
(?traverse@Traversal@@阿联酋?AV?$basic_string@DU?$char_traits@D@性病病毒$allocator@D@2@@std@@ABVGraph@@@Z)
 ;c:\Users\oben
isik\documents\visual studio
2010\Projects\hw2\hw2\main.obj
错误9错误LNK1120:1
未解析的外部c:\users\oben
isik\documents\visual studio
2010\Projects\hw2\Debug\hw2.exe 1
我现在能做什么?我只是想说,您真的不需要这样注释代码。每一行代码都应该是不言自明的,我认为在您的情况下确实如此,因此您确实不需要复制信息。您应该评论的是决策,例如,您使用了基于节点对象的图形实现(而不是基于边对象或边矩阵)。
#include "Graph.h"
#include "Traversal.h"