Home > Software design >  Use of class template node requires template arguments C
Use of class template node requires template arguments C

Time:12-31

I have two classes defined in C seen below.

#include <vector>
#include <tuple>
#include <map>

template <class T> class node   {
public:
    int NodeID;  //ID used to identify node when inserting/deleting/finding.
    T data;  //generic data encapsulated in each node.
    std::vector<node*> children;  //child nodes, list of ptrs
    std::vector<node*> parents;  //parent nodes list of ptrs
};


class DAG {//Class for the graph

    std::vector<node*> Nodes;

}

However I am getting an error within DAG saying "Use of class template node requires template arguments". I am completely lost any help is greatly appreciated.

CodePudding user response:

Solution 1

You can solve this by specifying a type in std::vector<node*> Nodes; as shown below:

std::vector<node<int>*> Nodes; //note i have added int you can add any type

Solution 2

Another solution would be to make class DAG a class template as shown below:

template<typename T>
class DAG {//Class for the graph

    std::vector<node<T>*> Nodes;

};
  • Related