1

I am making a class for graph, maybe i am not doing it the best way but the idea was to start for somewhere. I have this class graph.h

template <class T>
struct node
{
    int index;
    T name;
    vector<int> neighbours;
};

struct lengths{
    int node_1;
    int node_2;
    int length;
};

template <class T>
class graph : public vector<node<T>>
{
     public:
        graph();

     ...
}

and graph.cpp

template <class T>
graph<T>::graph(){
    directed = false;     //flag for dir graph, default false
    nodes = 0;               //number of nodes in the graph

}

and in main i have

graph<int> g;

but when i try to build it i get error

main.cpp undefined reference to `graph<char>::graph()'

I use GNU GCC Compiler [-std=c++14]

YMY
  • 13
  • 5
  • 1
    Dont implement templates in a seperate cpp. –  Aug 02 '17 at 14:25
  • in your header did you include the templated implementation/cpp file? – Samer Tufail Aug 02 '17 at 14:26
  • Duplication of https://stackoverflow.com/questions/9191210/templates-and-separate-compilation – ikleschenkov Aug 02 '17 at 14:31
  • Think about it. How can `graph::graph()` be compiled in isolation. The type is not known so there is nothing to compile. The error should be clearer, with vs14 `unrecognizable template declaration/definition` – lakeweb Aug 02 '17 at 14:37

0 Answers0