c++ - Why this code compiles in VS? ("extra" comma) -
the line below inside loop. if method fails, needs break. category_1 enum. added enum new parameter addtolist method default value. if see closely below, made mistake of putting comma , enum outside parameter list of function. compiles fine vs2010. had hard time finding that default value being passed parameter instead of category_1. know why succeeds?
if (! addtolist(obj1, (unsigned int) val), category_1) { break; }
in c++, comma isn't separator; can operator. comma operator. comma operator evaluates first expression, discards result, evaluates second expression , yields result.
!addtolist(obj1, (unsigned int) val) , category_1 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ first expression second expression [of course, comma operator, other operators, can overloaded, , if overload used here, semantics different. behavior of built-in comma operator.]
Comments
Post a Comment