How should C bitflag enumerations be translated into C++?
问题 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 ints convert back into enumeration values. Thus, bitflags defined via enumeration declarations don't work correctly. Hence, this is OK in C, but not in C++: typedef enum Foo { Foo_First = 1<<0, Foo_Second = 1<<1, } Foo; int main(void) { Foo x = Foo_First | Foo_Second; // error in C++ return 0; } How should this problem be