I was surprised to see a bit of syntax in a co-worker's code today.
void doSomething(bool& boolRef);
bool ok = true;
doSomething(ok = false);
I would think this is an error since the assignment operator in the param, ok = false, returns the value of the assigned value, which in this case is false. And since doSomething is expecting a reference, my first reaction was "that shouldn't work" since it would seem almost identical to doing doSomething(false);
But alas it does work. And reassigning the value of reference inside of doSomething works just like you'd expect.
Can someone please explain why this works?
Thank you!