I am learning C++14 lambdas with const, and today my friend showed me the following. I could not understand it.
Is it a lambda function? The syntax does not matches what I see usually.
it syntax matches with a lambda function, but it fails with a long error.
int main()
{
// 1.
const auto x = [&]{
auto l = 0;
l = 99;
return l;
}();
std::cout << x << endl;
// 2.
const auto y = [&](){
auto l = 0;
l = 99;
return l;
};
std::cout << y << endl;
return 0;
}
I want to know what 1 is, and why 2 fails to compile.