Учитывая функции:Почему авто не работает с некоторыми лямбдах
void foo(std::function<void(int, std::uint32_t, unsigned int)>& f)
{
f(1, 2, 4);
}
Почему это компиляции:
std::function<void(int a, std::uint32_t b, unsigned int c)> f =
[] (int a, std::uint32_t b, unsigned int c) -> void
{
std::cout << a << b << c << '\n';
return;
};
И это не удается скомпилировать:
auto f =
[] (int a, std::uint32_t b, unsigned int c) -> void
{
std::cout << a << b << c << '\n';
return;
};
С ошибкой :
5: error: no matching function for call to 'foo'
foo(f);
^~~
6: note: candidate function not viable: no known conversion from '(lambda at...:9)' to 'std::function<void (int, std::uint32_t, unsigned int)> &' for 1st argument
void foo(std::function<void(int, std::uint32_t, unsigned int)>& f)
^
Вы пробовали с различными компиляторами? Хорошая идея - попробовать как clang, так и gcc. – user1095108
Возможный дубликат: https://stackoverflow.com/questions/1565600 –