3 ms·
If this were just if (mouse = dynamic_cast<MouseEvent *>(event)) then it would indeed just be an if condition expression that happened to be an assignment
by jomar 13y ago
If this were just
if (mouse = dynamic_cast<MouseEvent *>(event))
then it would indeed just be an if condition expression that happened to be an assignment.
But the variable is being declared as well, so what's actually going on here is a declaration and an initialiser expression. There is actually new functionality here that needed a bit of language design thought, e.g., the declared variable's scope is the whole if statement, not just the condition expression.
- kelnos 13y agoI see this as no different than being able to do for (int i = 0; i < len; ++i) { }
- axusgrad 13y agoImagine my surprise, getting out of college and trying to use this at my job, when the compiler told me it was invalid! It wasn't obscure to me, but apparently was to the Sun Studio C++ compiler.