Resizing data of listed C ++ types

By default, enumerated type variables take the size of integers ie 4 bytes in memory. Is there any way to convert this to any other data type.

Not talking about type, but the size of memory needed to store an enumerated type. I raised this question. But he did not say about changing the integer size to any other. Any help.

+4
source share
2 answers

C ++ 11 introduced strongly typed enumerations (and strongly typed enumerations (version 3) ), which allows you to specify the basic type of an integral:

#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
+7
source

after reading some documentation on this website , I think this is not possible. This is actually logical. The enumerator lists only the list with the element referenced by the numbers. So the first question is what type or are you looking at? do you need an enumeration list for which an item should bing for int? Or you look at another type of type float char long .. in this case, I do not think it is possible

0
source

Source: https://habr.com/ru/post/1482341/


All Articles