我是新使用模板,並想知道我怎麼能做到以下幾點: 我有一個固定點結構,允許定點計算和定義如下:重映射模板參數結構
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個參數來聲明主模板,使'固定<位,偏移>'對於部分專業化的工作,我相信。 –