这是运行良好的代码:
template<typename... Args> struct count;
template<>
struct count<> {
static const int value = 0;
};
template<typename T, typename... Args>
struct count<T, Args...> {
static const int value = 1 + count<Args...>::value;
};
现在我想知道为什么我们需要部分专门化计数类模板?
我们可以做类似的事情:
template< typename... args> struct dd; // edited according to answer but now getting error redeclared with 2 template parameters which is point below with mark %%
template<>
struct dd<>{
static const int value = 0;
};
template<typename T, typename... args> //%%
struct dd{
static const int value= 1+ dd<args...>::value;
};
但这不起作用,但为什么?
非常感谢任何帮助:)
编辑:根据答案编辑解决方案。