在头文件和实现文件中创建模板模板函数

Create a template template function in header and implementation file

所以我有 class PolyLine,我试图将其通用化以允许 stl 容器(如列表或矢量)充当 class 容器。我正在尝试使用模板模板函数来执行此操作:

template<typename T, template<typename, typename> class Container, typename alloc = std::allocator<T>>
class PolyLine : public CAD::Shape {
private:
  size_t _n_points; //Number of points
  Container<T, alloc> _pline;
public:

  //Constructors
  PolyLine(size_t, double);
  PolyLine(const PolyLine&); //Copy constructor

  //Print
  void print();

  //Operator overload functions
  PolyLine& operator = (const PolyLine&);


};

我正在尝试像这样在实现文件中实现功能:

#include "PolyLine.hpp"

template<typename T, template<typename,typename> class Container, typename alloc = std::allocator<T>>
PolyLine<Container<T, alloc>>::PolyLine(size_t size, double distance) :  Shape(), _n_points(size) {
};

这不起作用,显然我需要在 PolyLine<Container<T,alloc>> 的声明中修复某些内容,但我不确定是什么。 *编辑:错误是 get is "PolyLine: too few template arguments".

您还没有为 Container<T, alloc> 特化 PolyLine,因此我们可以提供的唯一构造函数定义是默认特化 (PolyLine<T, Container, alloc>):

template<typename T, template<typename,typename> class Container, typename alloc>
PolyLine<T, Container, alloc>::PolyLine(size_t size, double distance) 
: Shape(), _n_points(size) 
{
}