How should C bitflag enumerations be translated into C++?

后端 未结 3 724
被撕碎了的回忆
被撕碎了的回忆 2021-01-14 14:58

C++ is mostly a superset of C, but not always. In particular, while enumeration values in both C and C++ implicitly convert into int, the reverse isn\'t true: only in C do i

3条回答
  •  心在旅途
    2021-01-14 15:20

    Either leave the result as an int or static_cast:

    Foo x = static_cast(Foo_First | Foo_Second); // not an error in C++
    

提交回复
热议问题