【发布时间】:2016-09-28 15:58:03
【问题描述】:
我尝试在元编程的阶乘示例中添加另一个模板参数。但以下不起作用。正确的方法是什么?
代码:
#include <iostream>
template <typename T, int Depth>
inline void loop(T i){
std::cout << i;
loop<T, Depth-1>(i - 1);
}
template <typename T, int Depth>
inline void loop<T, 0>(T i){
std::cout << i << std::endl;
}
int main(void){
int i = 10;
loop<int, 3>(i);
}
错误:
test4.cpp(9): error: an explicit template argument list is not allowed on this declaration
inline void loop<T, 0>(T i){
【问题讨论】:
标签: c++ templates metaprogramming template-meta-programming