OOP class definition release

I work for my homework in C ++, and I have some problems with multiplied definitions.

My graph class;

 class Graph{

     private:
          string name;                          //Graph name
          fstream* graphFile;                   //Graph 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 *);


};

and my bypass class;

 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();
};

My problem is in the traversal class, I need to declare the Graph class at the same time, in the graph class I need a traversal class to declare.

I have big problems with declerations :) Could you help me?

+3
source share
4 answers

, . , Graph Traversal . forward declartion, class BreadthFirst; Graph ( Graph {....}). class Graph; Traversal.

0

, acceptTraverse (Traversal *), - , .

+2

, ;

,

class BreadthFirst;
class DepthFirst;

traversal.cpp ;

#include "Graph.h"
#include "Traversal.h"

, ;

8 LNK2001: ": :: basic_string, std:: allocator > __thiscall Traversal:: traverse ( Graph const & ;)" (? @ @@? ..? $Basic_string @DU? $Char_traits @D @ @@V? $ @D @2 @@ @@ABVGraph @@@Z) nbsp; C:\Users\OBEN isik\\ 2010\Projects\HW2\HW2\main.obj

9 LNK1120: 1 c:\users\oben isik\\ 2010\Projects\hw2\Debug\hw2.exe 1

?

+1

, , Traversal,

Graph;

then he will know that the class of the graph will exist at some point

0
source

Source: https://habr.com/ru/post/1743443/


All Articles