From the course: Complete Guide to C++ Programming Foundations
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
Enumerations - C++ Tutorial
From the course: Complete Guide to C++ Programming Foundations
Enumerations
- [Instructor] Now 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 conversion between enums and integers, which is a safety hazard. A much better alternative that was introduced in the C++ 11 standard are enum classes. These are also known as scoped enums or strongly typed enums. Enum classes…
Contents
-
-
-
-
Basic data types2m 10s
-
(Locked)
Integer types2m 46s
-
(Locked)
Floating point types1m 29s
-
(Locked)
Variables2m 31s
-
(Locked)
Using variables5m 20s
-
(Locked)
Type aliases3m 58s
-
(Locked)
Enumerations8m 52s
-
(Locked)
Structures3m 13s
-
(Locked)
Type casting6m 18s
-
(Locked)
Type casting examples7m 2s
-
(Locked)
Type inference with auto4m
-
(Locked)
Solution: Data types1m
-
-
-
-
-
-
-
-
-