C++ overloaded function as template argument

You can give an explicit template argument:

bar<int(int)>(3, foo);

or cast the ambiguous function name to a type from which the template argument can be deduced:

bar(3, static_cast<int(*)(int)>(foo));

or wrap it in another function (or function object) to remove the ambiguity

bar(3, [](int x){return foo(x);});

Leave a Comment