I was playing around a bit with lambdas and binds and cannot understand why at the second call of f there is error with lambda closure cannot be converted into std::function<int(int)>. I kindly ask for an explanation. Thanks in advance.
#include <vector>
#include <functional>
void f(std::function<int(int)>f1, int x)
{
f1(x);
}
int g(int x, int y)
{
std::cout<<x+y;
return x;
}
int main()
{
f([](int x, int y = 10){std::cout<<x+y;return x;},20);
f([](int x, int y = 10){g(x,y);},20);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire