What is the difference between an enum and an enum class (scoped enumeration)?

Last updated 21 June 2026

A scoped enumeration (enum class) fixes the safety problems of a plain enum: it doesn't leak its enumerators into the surrounding scope and doesn't implicitly convert to integers.

  • Scope of enumerators: Plain enum names go into the enclosing scope, risking name clashes; enum class names are accessed as Color::Red.

  • Implicit conversion: A plain enum converts silently to int (error-prone in comparisons/arithmetic); a scoped enum requires an explicit static_cast.

  • Underlying type: Both can specify it (e.g. enum class E : std::uint8_t); scoped enums default to int, giving predictable size and forward declaration.

  • Rule of thumb: prefer enum class by default for type safety; use plain enum only for legacy/bit-flag interop convenience.

[lang:cpp] enum class Color { Red, Green }; Color c = Color::Red; // int x = c; // error: no implicit conversion int x = static_cast<int>(c); // explicit, intentional

  • https://www.geeksforgeeks.org/cpp/enum-classes-in-c-and-their-advantage-over-enum-datatype/
  • https://dev.to/pikotutorial/enums-vs-enum-class-in-c-3omn
  • https://dev.to/delta456/modern-c-enum-class-struct-m2f
All C++ interview questions