c++ ternary operator
问题 So I ran into something interesting that I didn't realize about the ternary operator (at least in Visual C++ 98-2010). As pointed out in http://msdn.microsoft.com/en-us/library/e4213hs1(VS.71).aspx if both the expression and conditional-expression are l-values the result is an l-value. Of course normally in c/c++ you'd write something like: int value = (x == 1) ? 1 : 0; and never even care about the r-value/l-value involvment, and in this case neither 1 nor 0 are convertible to l-values.