Scoped Enumerations

In this lesson, we will learn about Enumerations or Enums.

Enumerations conveniently define integer constants with names. These integer constants are called enumerators. Let’s go over some of the drawbacks of using classic enums.

Drawbacks of Enumerations in Classical C++

A short reminder. Three drawbacks of enumerations:

  1. The enumerators implicitly convert to int.
  2. They introduce the enumerators in the enclosing scope.
  3. The type of the enumeration cannot be specified.

Regarding point 3, enumerations cannot be forward declared since their type unknown. We can only the guarantee for the enumerators in classical C++. The type must be integral and large enough to hold the enumerators.

Points 1 and 2 are more surprising.

Get hands-on with 1200+ tech skills courses.