Say I have this function:
template <typename T>
void foo(function<T(const T&, const T&)> op, const T& lhs, const T& rhs) {
cout << op(lhs, rhs) << endl;
}
This is legal code:
function<int(const int&, const int&)> op = plus<int>();
foo(op, 13, 42);
But when I do this:
foo(plus<int>(), 13, 42)
I get the error:
No matching function for call to
foo(std::plus<int>, int, int)
Why can I initialize an object of type function<int(const int&, const int&)>
from plus<int>()
but I cannot pass plus<int>()
into an parameter of type function<T(const T&, const T&)>
? Is it something having to do with the template?