2
我正在嘗試explicitly instantiate a variadic構造函數。這個最小的例子print all arguments導致我在MinGW-w64 64位Win 7上看到與GCC 5.3相同的錯誤。顯式實例化可變參數構造函數:template-id與任何模板聲明不匹配
struct stf {
template<typename... Args> stf(Args&&... args){
using expand_type = int[];
expand_type{(print(args), 0)... };
}
};
//error on next line:
//template-id 'stf<char*, char*>' for 'stf::stf(char*, char*)'
//does not match any template declaration
template stf::stf<char*,char*>(char*,char*);
謝謝@Sam。我試圖從構造函數轉發參數,因此我找到了一個完美的轉發示例(上面沒有鏈接),然後找到了另外兩個示例。當我把所有東西放在一起時,我沒有注意到xvalue引用不是參數包的必需特徵......並且有一個例子有它們,有一個沒有。在我的辯護中,我只是一名機械工程師,我正在回頭修復幾年前我寫的一些舊代碼:-P –