I am learning C++14 lambdas with const, and today my friend showed me thisthe following. I could not understand 1. Is it a lambda function but the syntax does not matches what I see usually and the 2. syntax matches with lambda function but it fails with a long error.
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 wantedwant to know what is 1. is, and why 2. fails to compile.