我正在学习C ++,目前遇到类模板的奇怪问题。 这是我的头文件:
#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
这是我的.cpp文件:
#include "vector.h"
#include <list>
using std::ostream;
using namespace std;
template <int n>
Vector<n>::Vector(list<float> ncoords): coords {ncoords}{}
如果我Vector<2> vector;
但是如果我尝试,链接器会出错
Vector<20> vector2 { list<float>{} };
错误消息
未定义引用`Vector&lt; 20&gt; :: Vector(std :: list&gt;)'
问题是 - 我该如何解决这个问题?