How can I use an enum class in a boolean context?

后端 未结 7 1958
醉酒成梦
醉酒成梦 2021-01-07 15:59

I have some generic code that works with flags specified using C++11 enum class types. At one step, I\'d like to know if any of the bits in the flag are set. Cu

7条回答
  •  灰色年华
    2021-01-07 16:50

    No, not like that. Conversion operators must be members, and enums cannot have members. I think the best you can do is comparison with none, or, if there isn't a none enumerator, wrap the static_cast in a function.

提交回复
热议问题