C++, variable declaration in ‘if’ expression

As of C++17 what you were trying to do is finally possible:

if (int a = Func1(), b = Func2(); a && b)
{
    // Do stuff with a and b.
}

Note the use of ; of instead of , to separate the declaration and the actual condition.

Leave a Comment