我是新使用模板,并想知道我怎么能做到以下几点: 我有一个固定点结构,允许定点计算和定义如下:重映射模板参数结构
template<int bits, int offset>
struct Fixed {
int64_t raw;
inline Fixed() {}
...
}
我倒是想扩大,这样我可以声明一个自定义的浮点表示和编译器翻译这对正确的固定点的定义。我想这个如下:
template<int totBits, int expBits, int expOffset>
struct Fixed<exp2(expBits)+totBits-expBits-2,expOffset-totBits+expBits> {
inline Fixed() {}
inline explicit Fixed(double value) {
Quantization function of floating point here
}
};
然而,这给我的错误: “模板参数包括模板参数(S)”。
如何重新映射初始模板,以便我可以执行以下操作:fixed::Fixed<8,3,0> foo;
而编译器将此视为:fixed::Fixed<11,-3> foo;
?
我知道,当我一个值分配给foo
我将不得不手动quantise它,就好像它被存储为浮点:例如foo = fixed::Fixed<8,3,0>(243)
这将给富= 240和foo = fixed::Fixed<8,3,0>(244)
会给富= 248
你可以试试:'结构修正:修正了公众的''而不是固定结构' –
JVApen
@JVApen这让我再次声明与3个参数,而不是原来的声明,只有2个参数模板投诉。 –
@JVApen他需要用3个参数来声明主模板,使'固定<位,偏移>'对于部分专业化的工作,我相信。 –