- Example

Let's look at an example of how scoped enumerations can be used.

We'll cover the following

Example #

We can explicitly specify the type of enumerators. By default, it’s int.

But that does not have to be. We can use integral types like bool, char, short int, long int, or, long long int. Read msdn.microsoft.com for the details. See the post Check types for information on how to check if a type is integral at compile time.

We can use the scoped property and the explicit type specification of an enumeration independently. Depending on the base types, the enumerations can have different sizes.

Below is an example of the implementations of scoped enumerations using struct and class.

Get hands-on with 1200+ tech skills courses.