我有這個功能是AA可變參數模板功能:模板專業化
template<uint C>
double foo(){
double cpt = 1;
for(uint i=0; i<10; i++){
cpt += i*C;
}
return cpt;
}
template<uint C1, uint C2, uint... CCs>
double foo(){
double cpt = 1;
for(uint i=0; i<10; i++){
cpt += i*C1;
}
return cpt + foo<C2, CCs...>();
}
而且它完美的預期,但我認爲這是沒有做什麼,我想正確的方法做。 我試着寫類似的東西:
double foo(){
return 0;
}
template<uint C1, uint... CCs>
double foo(){
double cpt = 1;
for(uint i=0; i<10; i++){
cpt += i*C1;
}
return cpt + foo<CCs...>();
}
但我有錯誤no matching function for call foo() note: couldn't deduce template parameter C1
。 我也試過template <typename T>
在第一個foo
函數的頂部,但我有同樣的錯誤。
有人知道爲什麼嗎? 我使用g ++ 5.4和-std = C++ 11和-O3標誌。
'回報CPT + F();'能肯定Viridya? –
gsamaras
@gsamaras typo抱歉 – Viridya
[OT]:你可以擺脫循環,直接做'return(45 * C1 + 1)+ foo();' –
Jarod42