dimanche 6 août 2017

Compile error in a combining lambda captures

Someone asked me why this code does not compile:

int main()
{
    int a = 0;
    int x = 3, y = 2, z = 1;
    auto f = [&a,=]() { a = x + y + z; };
    f();
}

I've checked in Visual Studio 2017 and with wandbox for "gcc HEAD 8.0.0 201708" and it's true, it doesn't compile.

The first gcc error is just:

error: expected identifier before '=' token

on the line with the lambda, and it's complaining about the = in the capture clause.

What's wrong with the code?

Aucun commentaire:

Enregistrer un commentaire