I'm learning C++ and currently experiencing weird problem with Class template. This is my header file:
#ifndef VECTOR_H
#define VECTOR_H
#include <iostream>
#include <list>
using namespace std;
template <int n>
class Vector {
public:
list<float> coords;
Vector();
Vector(list<float> ncoords);
};
template <int n>
Vector<n>::Vector() {
coords.assign(n, 0.0);
}
#endif
And this is my .cpp file:
#include "vector.h"
#include <list>
using std::ostream;
using namespace std;
template <int n>
Vector<n>::Vector(list<float> ncoords): coords {ncoords}{}
Everything works fine if I do Vector<2> vector;
But linker gives an error if I try to
Vector<20> vector2 { list<float>{} };
Error message
undefined reference to `Vector<20>::Vector(std::list >)'
The question is - how can I solve this problem?