From the course: Learning C++

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Enumerations

Enumerations - C++ Tutorial

From the course: Learning C++

Enumerations

- [Instructor] It's time to introduce the concept of enumerations. In C++ an enumeration or enum, is a convenient way of defining a set of named integer constants. It is declared as a list of identifiers, known as enumerators, which are assigned consecutive integer values starting from zero. That's why it's called an enumeration. Now, enumerations of this type were inherited from the C programming language, so they weren't really designed with object-oriented programming in mind, and that makes them inappropriate for C++ code in most cases. One such problem is that C style enumerators exist in the global scope, which may lead to naming conflicts or namespace pollution. Another problem is that C style enums lack strong type checking, allowing implicit conversions between enums and integers, which is a safety hazard. A much better alternative that was introduced in the C++ 11 standard are enum classes, also known as…

Contents