【发布时间】:2017-05-06 16:04:09
【问题描述】:
我尝试将引用列表传递给可变参数模板函数并将其传递给另一个函数。我写的代码如下:
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吗? -
或多或少是的。但是,我的问题中的代码是对真实代码的简化。
标签: c++ c++11 variadic-templates reference-wrapper