Possible Duplicate:
what is the size of an enum type data in C++?
How is enum data type stored internally (I’d imagine as 8/16/32-bit int?) and can it be safely serialized or should I use something like quint8 to store the value? In other words is sizeof(MyEnum) guaranteed to be the same size on all platforms?
You can set an explicit type in C++11 (but not in earlier C++ incarnations):
or
Using
classin front ofenumby the way forces users ofDrugto spell itDrug::Cocaine, for enumerations without theclassin front of their declarations, the spelling is optional (bothSex::MaleandFemaleare valid).Hacks for C++es prior 2011 include the following, which forces a minimal size:
Seen in practice e.g. on ReactOS’ DirectX-SDK implementation.
Standards references