简体   繁体   English

没有用于调用可变参数包函数的匹配函数

[英]no matching function for call to a variadic parameter pack function

Consider: 考虑:

#include<tuple>

template<int N,typename... Vs,typename... Ts>
void fog( const std::tuple<Vs...>& vs , const std::tuple<Ts...> & ts )
{
}

template<typename...Vs,typename...Ts >
int gof( const std::tuple<Vs...>& vs , const std::tuple<Ts...> & ts )
{
  fog<0,Vs...,Ts...>(vs,ts);
}

int main()
{
  std::tuple<int,double> t;
  gof(t,t);
}

Why does the compiler (g++-4.6) not find the fog function and how to make it find it? 为什么编译器(g ++ - 4.6)找不到fog函数以及如何找到它?

error: no matching function for call to ‘fog(const std::tuple<int, double>&, const std::tuple<int, double>&)’
note: candidate is:
note: template<int N, class ... Vs, class ... Ts> void fog(const std::tuple<Vs ...>&, const std::tuple<_Tail ...>&)

Yes, I need the integral template parameter N . 是的,我需要积分模板参数N (This is a boiled down example.) (这是一个简单的例子。)

Don't expand the parameter packs: 不要展开参数包:

fog<0>(vs,ts);

Otherwise the compiler doesn't know which template parameters belong to which tuple. 否则,编译器不知道哪个模板参数属于哪个元组。 This way, the tuples' template parameters get deducted as usual. 这样,元组的模板参数就像往常一样被扣除。

Write: 写:

fog<0>(vs,ts);  

instead of 代替

fog<0,Vs...,Ts...>(vs,ts);

And let the compiler deduce the types. 让编译器推断出类型。

As for why the second form doesn't work, because the variadic parameter can be only the last parameter. 至于为什么第二种形式不起作用,因为可变参数只能是最后一个参数。 There cannot be two variadic template parameters of that form. 该表单不能有两个可变参数模板参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM