【发布时间】:2020-12-10 07:09:36
【问题描述】:
C++ 模板特化规则提到的特化必须比主模板更特化。跟随#1 代码 sn-p 导致编译错误,表示第二行不是更专业,但最后一个 sn-p (#2) 工作,看起来非常接近 #1。两个代码 sn-ps 都将 int N 专门化为 0,那么为什么第一个 sn-p 被抱怨为“没有更专门化”?
// #1
template<int N, typename T1, typename... Ts> struct B;
template<typename... Ts> struct B<0, Ts...> { }; // Error: not more specialized
// #2
template<int N, typename T1, typename... Ts> struct B;
template<typename T, typename... Ts> struct B<0, T, Ts...> { }; // this works
【问题讨论】: