I'm trying to understand why this piece of code will not compile:
void test_fff()
{
auto f1 = [](int x) {return x;};
decltype(f1) f2 = [](int y) {return y;};
}
This is the compile error I'm getting:
error: conversion from 'test_fff()::<lambda(int)>' to non-scalar type 'test_fff()::<lambda(int)>' requested 177 | decltype(f1) f2 = [](int y) -> int {return y;};
I'm using g++ 10.2.0 with -std=c++17
However, this code compiles just fine:
void test_fff()
{
FFF<decltype(2)>::foo(2);
std::function<int (int)> f1 = [](int x) {return x;};
decltype(f1) f2 = [](int y) {return y;};
}
What's the difference between the two?