Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 VS 10 中,我收到警告:
warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
试图编译
int x ; static_cast<bool>(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
这是一个愚蠢的警告,可以忽略/禁用。据我所知,没有性能问题。