简体   繁体   English

找不到匹配的重载函数C ++ TEMPLATE

[英]No matching overloaded function found C++ TEMPLATE

Recurvise call C++ template function with Variable template 使用Variable模板递归调用C ++模板函数

void int void foo()
{

}

template <typename T, typename ...U> void foo()
{
    foo<U...>();
}

int main()
{
    foo<int, char, int>();
    return 0;
}

The compile meesage such as: 编译消息如:

error C2672: 'foo': no matching overloaded function found note: see reference to function template instantiation 'void foo(void)' being compiled note: see reference to function template instantiation 'void foo(void)' being compiled note: see reference to function template instantiation 'void foo(void)' being compiled error C2783: 'void foo(void)': could not deduce template argument for 'T' note: see declaration of 'foo' 错误C2672:'foo':未找到匹配的重载函数注意:请参见对正在编译的函数模板实例化'void foo(void)'的引用注意:请参见对正在编译的函数模板实例化'void foo(void)'的说明注意:请参见参考到正在编译的函数模板实例化'void foo(void)'的错误C2783:'void foo(void)':无法推断'T'的模板参数注意:请参见'foo'的声明

I declare the void foo(void), Why the error occured? 我声明void foo(void),为什么会发生错误? complier can match template void foo(), but can't match void foo(void) 编译器可以匹配模板void foo(),但是不能匹配void foo(void)

Assuming your base case is void foo() {} , in your recursive case you're performing the following function invocations: 假设您的基本情况为void foo() {} ,那么在递归情况下,您将执行以下函数调用:

foo<int, char, int>();
foo<char, int>();
foo<int>();
foo<>();

Notice that the last invocation is foo<>(); 注意,最后一次调用是foo<>(); rather than foo(); 而不是foo(); . The compiler error is due to the fact that your base case of void foo() {} cannot be called with the foo<>(); 编译器错误是由于以下事实造成的:您无法使用foo<>();来调用void foo() {}基本情况foo<>(); syntax. 句法。

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

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