






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An overview of the new features in C++11 related to enums, specifically strongly-typed enums and their forward declarations. It covers the problems with traditional enums, the concept of unscoped and scoped enumerations, and the benefits of using strongly-typed enums. It also includes examples and references for further learning.
What you will learn
Typology: Lecture notes
1 / 10
This page cannot be seen from the preview
Don't miss anything!
7/13/2015 | Page Division
7/13/2015 | Page Division
enum name { enumerator = constexpr , enumerator = constexpr , ... }
enum name : type { enumerator = constexpr , enumerator = constexpr , ... }
7/13/2015 | Page Division EXAMPLE TRADITIONAL ENUMS enum Color { red, yellow, green= 20 , blue }; Color col = red; int n = blue; // n == 21 struct Foo { enum Direction { left='l', right='r' }; }; Foo x; int a = Foo::left; int b = x.left; int c = Foo::Direction::left; // allowed only in C++11 and later
7/13/2015 | Page Division EXAMPLE IMPLICIT CONVERSION enum class Color { RED, GREEN= 20 , BLUE }; Color r = Color::BLUE; switch(r) { case Color::RED : std::cout << "red" "\n"; break; case Color::GREEN : std::cout << "green" "\n"; break; case Color::BLUE : std::cout << "blue" "\n"; break; } int n = r; // error: no scoped enum to int conversion int n = static_cast
7/13/2015 | Page Division EXAMPLE ENUM FORWARD DECLARATION
7/13/2015 | Page Division