How can an array work with the conditional operator?

回眸只為那壹抹淺笑 提交于 2019-12-06 02:43:35

Your analysis is correct. I suspect that the non-void operand is 'decayed' (that is, the usual conversions are performed) in such a situation so as to mimic what happens when the two operands differ in types -- in the latter case more often than not the whole conditional expression is a prvalue.

One situation in which we know for sure both value category and type of a conditional expression is when the two operands are exact matches, so we can use that to our advantage:

cond ? (throw e, t) : t

will be an lvalue of array reference type. (Of course the last operand doesn't have to be literally t -- you can plug your recursive call here just fine.)

You did not encounter any such hurdle when using if/else because as a statement the language does not have to specify a common type and value category for it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!