以下代码给了我一个编译错误: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)));
}
怎么了?我正在尝试将
grid_residue
专门用于Q64
类。更新:
语法已更改。现在收到错误
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)));
}
谢谢
最佳答案
功能不能部分特化!使用函数重载:template <int GRIDD> inline Q64 grid_residue(Q64 amount)
或将函数包装为类型(可以是部分专用的)。
关于C++模板部分特化错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4603220/