I have a scoped enum that I am using as bit flags and I am trying to figure out how to use the results in an if statement (return boolean)
Example:
enum class Fruit {
NoFruit = 0x00,
Apple = 0x01,
Orange = 0x02,
Banana = 0x04 };
inline Fruit operator & (Fruit lhs, Fruit rhs) {
return (Fruit)(static_cast<int16_t>(lhs) & static_cast<int16_t>(rhs));
}
Is it possible to below I without writing == Fruit::NoFruit, right now I get the error "expression must have bool type (or be convertible to a bool)"
Fruit test_fruit = Fruit::Apple;
// Not possible, have to write
// if((test_fruit & Fruit::Apple) == Fruit::NoFruit)
if(test_fruit & Fruit::Apple) {
// do something
}