简体   繁体   English

c ++模板中的部分特化:模板参数不可推导

[英]Partial specialization in c++ template : template parameter not deducible

The below code works fine : 以下代码工作正常:

template<typename T, int n> 
class Fib {};

template<typename T,int n>
class Fib<T*,n> {}; 

But the below code shows error as: 但是下面的代码显示错误:

Error : template parameters not deducible in partial specialization: 错误:模板参数在部分特化中无法推导:

 template<typename T, int n> 
 class Fib {};

 template<typename T,int n>
 class Fib<T*,0> {};

Can you explain the reason for this behaviour ? 你能解释一下这种行为的原因吗?

I believe you are just missing the right syntax for the partial specialization: 我相信你只是缺少部分特化的正确语法:

template<typename T, int n> 
 class Fib {

 };

 template<typename T>
 class Fib<T*,0> {

 };

The first parameter on the template is type, while the second is just a constant value. 模板上的第一个参数是type,而第二个参数只是一个常量值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM