Answer the question
In order to leave comments, you need to log in
Link to lambda?
The simplest lambda:
auto lsqr = [](const int &n) -> int { return n*n; };
int (*pointer)(const int&) = lsqr; // Нормально
int (&refernce)(const int&) = lsqr; // Ошибка
//Нормально, извращение
int (&perversion)(const int&) = *(int(*)(const int&)) lsqr;
Answer the question
In order to leave comments, you need to log in
For lambdas that do not capture variables in their [], a conversion operator to a function pointer is defined (ClosureType::operator ret(*)(params)()). That's why there is an implicit cast in your 1st example. The compiler does not find a suitable conversion for the reference.
The last example first converts the lambda to a pointer and dereferences it as just a pointer.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question