No matching overloaded function found C++ TEMPLATE

Recurvise call C++ template function with Variable template

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'

I declare the void foo(void), Why the error occured? complier can match template void foo(), but can't match void foo(void)


Assuming your base case is void foo() {} , in your recursive case you're performing the following function invocations:

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

Notice that the last invocation is foo<>(); rather than foo(); . The compiler error is due to the fact that your base case of void foo() {} cannot be called with the foo<>(); syntax.

链接地址: http://www.djcxy.com/p/66540.html

上一篇: 使用JavaScript进行自定义目的

下一篇: 找不到匹配的重载函数C ++ TEMPLATE