【发布时间】:2018-01-28 17:08:05
【问题描述】:
我正在尝试专门化一个函数模板,但我遇到了一个错误(标题),我不知道如何解决它。我猜这是由于我在模板专业化中使用的混合类型。这个想法只是在专业化中使用 int 作为 double 。非常感谢。
template <typename T>
T test(T x) { return x*x; }
template <>
double test<int>(int x) { return test<double>(x); }
【问题讨论】:
-
double test(int)不匹配T test(T),因此出现错误。
标签: c++ templates template-specialization