From the course: Learning C++
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
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
-
-
-
-
(Locked)
Basic data types3m 44s
-
Variables2m 6s
-
(Locked)
Using variables5m 18s
-
Expressions, assignments, and operations3m 52s
-
(Locked)
Type inference with auto3m 5s
-
(Locked)
Preprocessor directives7m 10s
-
(Locked)
Constants1m 58s
-
Arrays6m 44s
-
(Locked)
Strings5m 42s
-
(Locked)
Type casting4m 34s
-
(Locked)
Type casting examples5m 13s
-
(Locked)
Enumerations7m 55s
-
(Locked)
Challenge: Calculate an average57s
-
(Locked)
Solution: Calculate an average54s
-
(Locked)
-
-
-
-
-