dimanche 20 mars 2022

implementation of the graph class

I tried to implement class the graph T in c++ visual studio, writing a program

template <class T>
class Graph;

template <class T>
class Vertex
{
private:
     T data;
     Vertex<T>* next;
public:
     friend class Graph<T>;
     Vertex(T dat, Vertex<T>* nex)
     {
          data = dat;  next = nex;
     }
 };


 template <class T>
 class Graph
 {
 public:
     Vertex<T>* head;
     Graph() : head(NULL)
     {
     }



     void insert(T data)
     {
           Vertex<T>* ptr = new Vertex<T>(data, head);
           head = ptr;
     }
 };

And I get an error:

NULL: ID not found

what should I do to fix this?

Aucun commentaire:

Enregistrer un commentaire