Compiler implicitly does the unscoped enum to integral conversion. Conversion of integral to enum is not implicit and we need to explicitly do this.

enum Color
{
    red,
    green,
    blue,
};
 
Color value{1}; // compilation error

Using static_cast

We can use static_cast to explicitly convert integral value to enum as shown below:

Color value{static_cast<Color>(1)};

This would work and value would be green.

Other method using list initialization

If we have specified explicit base for enum, we can use list initialization to initialize an integral to an enum type.

enum Theme : std::int8_t
{
    dark,
    light
};
 
 
Theme theme{1}; // list initialization
std::cout << theme << "\n";

References

  1. https://www.learncpp.com/cpp-tutorial/unscoped-enumerator-integral-conversions/