Home No matching overloaded function found C++ TEMPLATE
Reply: 1

No matching overloaded function found C++ TEMPLATE

fanwenjie
1#
fanwenjie Published in 2017-11-17 01:48:34Z

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)

mpark
2#
mpark Reply to 2017-11-17 02:12:52Z

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.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.344323 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO