Hi there.
I was wondering why the following two constructions dont work as expected:
1.) bool a, b, c, d = false;
bool a = false, b = false, c = false, d = false;
You have to initialize each one separately. Often the advice in C++ is
to have only 1 variable per declaration. e.g.
bool a = false;
bool b = false;
bool c = false;
bool d = false;
is clearer.
2.) bool a, b, c, d;
a, b, c, d = false;
The comma operator is used to separate expressions and return the
right hand expression. So that is exquivalent to:
evaluate a, discard the value
evaluate b, discard the value
evaluate c, discard the value
evaluate "d = false", discard the value.
So only d is modified.
Using the comma operator in an unusual way:
a = false, b = false, c = false, d = false;
or in conventional syntax:
a = false; b = false; c = false; d = false;
But the following works.
bool a, b, c, d;
a = b = c = d = false;
It should be obvious why that works, but for the others you just have
to understand declaration syntax and the comma operator.
Tom
C++ FAQ:
http://www.parashift.com/c++-faq-lite/
C FAQ:
http://www.eskimo.com/~scs/C-faq/top.html