Is it possible to manually define a conversion for an enum class?

No, it’s not.

Actually, an enum class is no class at all. The class keyword is only used because suddenly changing the unscoped enum to a scoped enum would have mean reworking all enums codes. So the committee decided that to distinguish between new-style and old-style enums, the new ones would be tagged with class, because it’s a keyword already so no enum could have been named class in C++. They could have picked another, it would not have made much more sense anyway.

However, despite the class keyword they are still regular enums in that only enumerators (and potentially values assigned to them) are allowed within the brackets.

Leave a Comment