我嘗試傳遞給variadic模板函數一個引用列表並將它傳遞給另一個函數。我寫的代碼如下:將引用傳遞給variadic-templates使用std :: reference-wrapper
template <typename T>
void fun(cv::Point_<T> & pt) { pt.x++; pt.y++; }
template <class ... args>
void caller(args & ... list) {
typedef typename std::tuple_element<0, std::tuple<args...> >::type T;
std::array<std::reference_wrapper<T>, sizeof...(list)> values {list ... };
for(int i=0; i<values.size(); i++)
fun(values[i]);
}
然後我把這樣的函數調用:
cv::Point2f a, b, c;
caller(a, b, c);
編譯器給我下面的錯誤:
No matching function for call to 'fun'
Candidate template ignored: could not match 'Point_' against 'reference_wrapper'
我失蹤?
你想做什麼?引用包裝只是多餘的。你是否真的試圖爲每個參數調用'fun'? –
或多或少是的。然而,我的問題中的代碼是對真實代碼的簡化。 – thewoz