why can enum class values of type int not be used as int

后端 未结 4 659
再見小時候
再見小時候 2021-01-28 20:29

I wanted to change an old-style enum to enum class : int because of its own scope.

But the compiler complains about using the values in integer

4条回答
  •  半阙折子戏
    2021-01-28 21:13

    You can convert them explicitly via a static_cast.

      int id = (static_cast(MsgType::Input) << 16) + (static_cast(MsgSender::A)) ;
    

提交回复
热议问题