C++模板部分特化错误
下面的代码给了我一个编译错误:class Q64 is not a valid type for a templateconstant argument
template<int GRIDD, class T>
INLINE T grid_residue(T amount) {
T rem = amount%(GRIDD);
if (rem > GRIDD/2) rem -= GRIDD;
return rem;
}
template<int GRIDD, Q64>
INLINE Q64 grid_residue(Q64 amount) {
return Q64(grid_residue<GRIDD, int64_t>(to_int(amount)));
}
出了什么问题?我正在尝试将grid_residue
专门用于Q64
类。
更新:
更改了语法。现在出现错误错误:函数模板部分特化'grid_residue
template<int GRIDD>
INLINE Q64 grid_residue(Q64 amount) {
return Q64(grid_residue<GRIDD, int>(to_int(amount)));
}
谢谢
The following code is giving me a compilation error: class Q64 is not a valid type for a template constant parameter
template<int GRIDD, class T>
INLINE T grid_residue(T amount) {
T rem = amount%(GRIDD);
if (rem > GRIDD/2) rem -= GRIDD;
return rem;
}
template<int GRIDD, Q64>
INLINE Q64 grid_residue(Q64 amount) {
return Q64(grid_residue<GRIDD, int64_t>(to_int(amount)));
}
Whats wrong? I am trying to specialize grid_residue
for class Q64
.
UPDATE:
Changed syntax. Now getting error error: function template partial specialization 'grid_residue<GRIDD, Q64>' is not allowed
template<int GRIDD>
INLINE Q64 grid_residue(Q64 amount) {
return Q64(grid_residue<GRIDD, int>(to_int(amount)));
}
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
函数不能部分特化!要么使用函数重载:
template;内联 Q64 grid_residue(Q64 amount)
或将函数包装在类型中(可以部分专门化)。Functions cannot be partially specialized! Either use function overloading:
template <int GRIDD> inline Q64 grid_residue(Q64 amount)
or wrap your function in a type (which can be partially specialized).您不能部分特化函数。
You cannot partially specialise functions.
编译/链接正常(VS2010)。
Compiles/links ok (VS2010).