gpt4 book ai didi

c++ - [expr.cond]/2 是不是少了什么?

转载 作者:行者123 更新时间:2023-11-30 05:06:04 25 4
gpt4 key购买 nike

[expr.cond]/2 :

2 If either the second or the third operand has type void, one of the following shall hold:

(2.1) — The second or the third operand (but not both) is a (possibly parenthesized) throw-expression (8.17); the result is of the type and value category of the other. The conditional-expression is a bit-field if that operand is a bit-field.

(2.2) — Both the second and the third operands have type void; the result is of type void and is a prvalue. [ Note: This includes the case where both operands are throw-expressions. —end note ]

考虑第二个操作数的类型为 void 的情况,但它不是 throw 表达式,而第三个操作数是 throw 表达式。这种情况属于 (2.1) 还是 (2.2)?

最佳答案

案例2.1有条件:

(the second operand is a throw-expression) XOR (the third operand is a throw-expression)

案例2.2有条件:

(the second operand has type void) AND (the third operand has type void)

因此,如果恰好有一个操作数是 throw-expression 而另一个操作数的类型为 void,则属于情况 2.1。另一个操作数的类型为 void 的事实意味着条件表达式的结果具有类型 void (由于分号后面的子句),但它不会改变事实上,我们在案例 2.1 中。

关于c++ - [expr.cond]/2 是不是少了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48118403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com