在VS 10,我得到一個警告:INT爲bool鑄造
warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
試圖編譯
int x ;
static_cast<bool>(x);
怎麼可能寫出這不`噸導致此警告代碼?
在VS 10,我得到一個警告:INT爲bool鑄造
warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
試圖編譯
int x ;
static_cast<bool>(x);
怎麼可能寫出這不`噸導致此警告代碼?
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
怎麼樣的東西是:
x != 0
其中有更清晰的優勢。 –
這是一個愚蠢的警告,可以忽略/禁用。據我所知,沒有性能問題。
這不是一個錯誤,它是一個警告。 –
關閉警告。 –