14.16 Boolean expressions

王朝other·作者佚名  2006-05-04
窄屏简体版  字體: |||超大  

A boolean-expression is an expression that yields a result of type bool.

boolean-expression:

expression

The controlling conditional expression of an if-statement (?5.7.1),

while-statement (?5.8.1), do-statement

(?5.8.2), or for-statement (?5.8.3) is a boolean-expression. The

controlling conditional expression of the

?: operator (?4.12) follows the same rules as a boolean-expression, but

for reasons of operator precedence

is classified as a conditional-or-expression.

A boolean-expression is required to be of a type that can be implicitly

converted to bool or of a type that

implements operator true. [Note: As required by ?7.9.1, any type that

implements operator true

must also implement operator false. end note] If neither requirement is

satisfied, a compile-time error

occurs.

When a boolean expression is of a type that cannot be implicitly converted

to bool but does implement

operator true, then following evaluation of the expression, the operator

true implementation

provided by that type is invoked to produce a bool value.

[Note: The DBBool struct type in ?8.4.2 provides an example of a type that

implements operator true

and operator false. end note]

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航