I have a template that accepts a function as an argument.
When I try to pass a lambda expression it does not compile.
typedef int (*func)(int a);
te
This is because the lambda as its own type.
You have templatize function() on the type of the function passed.
template
int function(F foo, int a) {
return foo(a);
}
int test(int a) {
return a;
}
int main()
{
// function will work out the template types
// based on the parameters.
function(test, 1);
function([](int a) -> int { return a; }, 1);
}