C++ 整型铸造

C++ 整型铸造,c++,casting,boolean,int,warnings,C++,Casting,Boolean,Int,Warnings,在VS 10中,我得到一个警告: warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning) 试图编译 int x ; static_cast<bool>(x); intx; 静态铸型(x); 如何编写一个不引起此警告的代码?以下内容如何: x != 0 这是一个愚蠢的警告,可以忽略/禁用。据我所知,没有性能问题。这不是错误,而是警告。 int x ; bool b1

在VS 10中,我得到一个警告:

warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
试图编译

int x ;
static_cast<bool>(x);
intx;
静态铸型(x);

如何编写一个不引起此警告的代码?

以下内容如何:

x != 0

这是一个愚蠢的警告,可以忽略/禁用。据我所知,没有性能问题。

这不是错误,而是警告。
int x ;
bool b1 = !!x;  // common idiom; get used to it.  "Newcomers" just need to learn the idiom.
bool b2 = x!=0; // another way, less idiomatic