Specifying the Size of an enum

Image

Although each enum defines a unique type, it is represented by one of the built-in integral types. Under the new standard, we may specify that type by following the enum name with a colon and the name of the type we want to use:

enum intValues : unsigned long long {    charTyp = 255, shortTyp = 65535, intTyp = 65535,    longTyp = 4294967295UL,    long_longTyp = 18446744073709551615ULL};

If we do not specify the underlying type, then by default scoped enums have int as the underlying type. There is no default for unscoped enums; all we know is that the underlying type is large enough to hold the enumerator values. ...

Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.