Scoped Enumerations (C++11)
Traditional enumerations have some problems. One is that enumerators from two different enum definitions can conflict. Suppose you were working on a project involving eggs and T-shirts. You might try something like this:
enum egg {Small, Medium, Large, Jumbo};enum t_shirt {Small, Medium, Large, Xlarge};
This won’t fly because the egg Small and the t_shirt Small would both be in the same scope, and the names conflict. C++11 provides a new form of enumeration that avoids this problem by having class scope for its enumerators. The declarations for this form look like this:
enum class egg {Small, Medium, Large, Jumbo};enum class t_shirt {Small, Medium, Large, Xlarge};
Alternatively, you can use the keyword struct instead ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access