Enums & Structs in C++

From the C++ cheat sheet · Enums & Structs · verified Jul 2026

Enums & Structs

enum class and aggregate structs.

cpp
// Quick Reference
enum class Color { Red, Green, Blue };
Color c = Color::Red;

struct Point { int x; int y; };
Point p{3, 4};
💡 Prefer enum class over plain enum - it scopes names and blocks implicit int conversion.
⚡ struct and class are identical except structs default to public members.
📌 Aggregate init Point{3, 4} sets members in declaration order.
🟢 Give struct members default initializers (int x = 0;) so partial init stays safe.
enumsstructs
Back to the full C++ cheat sheet