By default enumerated type variables take the size of integer i.e 4 bytes in memory. Is there any way to convert this to any other data type size.
Am not talking about type casting, but the memory size required to store an enumerated type.I have referred this question But it didn't tell about changing the integer size to any other.Any help.
c++11 introduced strongly typed enums (and Strongly Typed Enums (Revision 3)), which permits the specification of the underlying integral type:
#include <iostream>
enum E_ushort : unsigned short { EUS_1, EUS_2 };
enum E_ulong : unsigned long { EUL_1, EUL_2 };
int main()
{
std::cout << sizeof(E_ushort::EUS_1) << "\n";
std::cout << sizeof(E_ulong::EUL_1) << "\n";
return 0;
}
Output:
2 4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With