C++ › Enums & Enum Classes

Can you forward declare an enum, and what are the rules?

Intermediate

Answer

A scoped enum (or an unscoped enum with an explicit underlying type) can be forward declared because its size is known. A plain unscoped enum without a specified underlying type cannot be forward declared, since its size depends on its values. Forward declaration reduces header dependencies.
enum class Color : int;   // forward declaration OK
enum Plain;               // error without underlying type
Real-world example Forward declaring an enum class in a header avoids pulling in the full definition, cutting compile dependencies.

Common follow-ups: Why can't a plain enum be forward declared? | What makes an enum forward-declarable?