模板模板参数的模板专用化

Template Specialization for Template Template Parameter

本文关键字:专用 参数      更新时间:2023-10-16

>我在 .h 文件中创建了一个模板模板参数的模板类:

template<typename Index=Date, typename Value=double, template<typename> 
class Container=std::vector> class FastDataSeries 

然后我尝试将其专门化.cpp文件中,以便利用其他文件中的C++11"外部模板"功能,

    template<> class FastDataSeries <Date, double, std::vector >;
    template<> class FastDataSeries <int, double, std::vector >;

然后我收到如下错误消息:

../src/timeseries/FastDataSeries.cpp:13:61:错误:类型/值不匹配 在"模板类容器"的模板参数列表中的参数 3 处>类 市场风险::快速数据系列的模板<>类快速数据系列; ^ ../src/timeseries/FastDataSeries.cpp:13:61:错误:预期为 类型为"模板类容器"的模板,得到 '模板类 std::vector' ../src/timeseries/FastDataSeries.cpp:14:60:错误:类型/值不匹配 在"模板类容器"的模板参数列表中的参数 3 处>类 市场风险::快速数据系列的模板<>类快速数据系列; ^ ../src/timeseries/FastDataSeries.cpp:14:60:错误:预期为 类型为"模板类容器"的模板,得到 '模板类 std::vector' 制作: *** [src/timeseries/FastDataSeries.o]错误 1

这样做的正确语法是什么?

template<typename>

这与 std::vector 的模板不匹配。您必须提供所有模板参数。

template<class T, class Allocator = std::allocator<T> class Container