Enums and Structs
enum class defines scoped, type safe constants. A struct groups related data with public members by default.
Example
enum class Color { Red, Green, Blue };
struct Point { int x, y; };
Color c = Color::Green;
Point p{3, 4};
cout << static_cast<int>(c) << " " << p.x + p.y << "\n";Result
1 7
Exercise
Scoped enum.
enum Color { Red };
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.