Jes*_*per 57
不,if (c)是一样的if (c != 0).和if (!c)是一样的if (c == 0).
D.S*_*ley 23
我会打破这个......" if (c)"最接近" if (((bool)c) == true)".对于整数类型,这意味着" if (c != 0)".正如其他人所指出的那样,超载operator !=可能会引起一些陌生感,但operator bool()除非我弄错,否则会超载" ".
如果c是指针或数值,
if( c )
Run Code Online (Sandbox Code Playgroud)
相当于
if( c != 0 )
Run Code Online (Sandbox Code Playgroud)
如果c是布尔值(类型为bool [only C++]),(编辑:或用户定义的类型,运算符bool()的重载)
if( c )
Run Code Online (Sandbox Code Playgroud)
相当于
if( c == true )
Run Code Online (Sandbox Code Playgroud)
如果c也不是指针或数值都不是布尔值,
if( c )
Run Code Online (Sandbox Code Playgroud)
不会编译.
| 归档时间: |
|
| 查看次数: |
29617 次 |
| 最近记录: |