【发布时间】:2016-11-14 18:12:14
【问题描述】:
我想要一个函数,将一个值倒数为零。另外,我想调用一些代码,哪个类作为模板参数传递。 但这段代码不起作用。请问有人可以帮我吗? 非常感谢。
错误信息是:
"不允许函数模板偏特化'foo'"
class Hello_World
{
public:
void hello(size_t number){
cout << "hello " << number << endl;
}
};
template<size_t SIZE, class T>
void foo()
{
T t;
t.hello(SIZE);
foo<SIZE-1, Hello_World>();
}
template<class T>
void foo<0,T>()
{
cout << "end." << endl;
}
int main()
{
foo<4,Hello_World>();
}
【问题讨论】:
-
什么不起作用,到目前为止你尝试了什么,是不编译,崩溃,......?
-
请提供minimal reproducible example 和您收到的错误消息。由于多种原因,此代码无法编译。