31

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);
}
guptha
  • 533
  • 1
  • 4
  • 9
user3157184
  • 329
  • 1
  • 3
  • 4

3 Answers3

56

FYI: Casts won't hide the warning by design.

Something like

return (id & MID_NUMBER) != 0;

should clearly state "I want to check whether this value is zero or not" and let the compiler be happy

Marco A.
  • 42,082
  • 25
  • 129
  • 240
2

Use the !! idiom eg

bool CBase::isNumber()
{
    return !!(id & MID_NUMBER);
}
cup
  • 6,937
  • 3
  • 16
  • 40
2

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.

Vman
  • 2,876
  • 1
  • 23
  • 19