enum makes it possible to define integral values with meaningful names, without defining constants and giving them a separate type.
enum status {open, closed};
void foo(status s);
foo(open);
foo(closed);
foo(42); // does not compileThe downsides of enum is that it is "global", as it is not possible to reuse the identifier in other places.
It also converts implicitely to other integral types:
enum status {open, closed};
bool closed = false; // does not compile
open + closed; // compilesenum class shares many of the properties of an enum, but
-
introduces a new scope
-
does not convert implicitely to integral types
enum class status {open, closed};
void foo(status s);
foo(status::open);
foo(status::closed);
foo(42); // does not compile
bool closed = false; // compiles
status::open + status::closed; // does not compile