C++ 警告 C4800:“int”:强制值布尔值“true”或“false”(性能警告)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20919650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
提问by user3157184
I have this problem in my code:
我的代码中有这个问题:
bool CBase::isNumber()
{
return (id & MID_NUMBER);
}
bool CBase::isVar()
{
return (id & MID_VARIABLE);
}
bool CBase::isSymbol()
{
return (id & MID_SYMBOL);
}
回答by Marco A.
回答by cup
Use the !! idiom eg
使用 !!习语例如
bool CBase::isNumber()
{
return !!(id & MID_NUMBER);
}
回答by Vman
Where's the declaration of id and MID_NUMBER? Are you sure they are not windef-style BOOLs rather than (lowercase) bool's? BOOL's have been in windef for decades typedef'd as an int; they pre-date proper C++ bool's and a lot of developers still use them.
id 和 MID_NUMBER 的声明在哪里?您确定它们不是 Windef 风格的 BOOL 而不是(小写)bool 吗?几十年来,BOOL 一直在windef 中被定义为一个int;它们早于适当的 C++ bool 并且许多开发人员仍在使用它们。