mardi 30 décembre 2014

Why are lambda arguments passed by value read-only in C++11?

When a function takes an argument by value, it can usually modify it. However, this does not seem to be the case with lambdas. Why?



int main()
{
int x = 0;
auto lambda = [x] { x = 1; }; // error: assignment of read-only variable ‘x’
return 0;
}

Aucun commentaire:

Enregistrer un commentaire