Date: Mon, 20 Apr 2026 16:00:28 +0500
You do have a point that inheritance with enum classes would be great for
group enums together, but can't we do it already? Like:
enum class base_enum{red, Violet, blue};
Struct base{
using Type= base_enum;
};
enum class derived_enum{red, Violet, blue};
Struct derived:base{
using Type= base_enum;
};
This would allow you to pass derived where base is expected and use the
Type of derived. Inheriting enumerators on the other hand would not be a
good idea since you are mixing enums instead of group them.
On Mon, 20 Apr 2026, 3:47 pm Andrey Fokin via Std-Proposals, <
std-proposals_at_[hidden]> wrote:
> Title: Pxxxx: Add inheritance for Enum Class enumerations
> Author: Andrey Fokin, lazzyfox_at_[hidden]
> Date: 2026-04-20
> Project: Programming Language C++, Library Working Group
> Abstract: New inheritance feature to enum class (scoped enumerations)
> 1. Introduction
> According my experience the are situations when scped enumerations could
> be presented in OOP style – base enumeration type and some ancestors of.
> For example – we have to define a list of colors for traffic lights device.
> Is simple case we have just three colors and our enum could looks like
> enum class TrafficLight:uint8_t { Red, Yellow, Green };
> And probably this enum will cover biggest part of cases. But if we need to
> have a case wit Trafficligt wit left, rgih or two arrows we need ot use
> three diffeerent data types for each with big part of duplicated data in
> eatch.
> Case 1- additional letf arrow enum class TrafficLight_LefatArrow:uint8_t {
> Red, Yellow, Green, LeftArrow };
> Case 2- additional right arrow enum class TrafficLight_RightArrow:uint8_t
> { Red, Yellow, Green, RightArrow };
> Case 3- two additional arrows enum class TrafficLight_TwoArrows:uint8_t {
> Red, Yellow, Green, LeftArrow, RightArrow };
>
> In case of inheritance could be possible use as first case as a base class
> and athers as inherited to exclude overlapping data duplication and casese
> above cold looks like
> Case 4- additional letf arrow enum class TrafficLight:LefatArrow:uint8_t
> {LeftArrow };
> Case 5- additional right arrow enum class TrafficLight:RightArrow:uint8_t
> {RightArrow };
> Case 6- two additional arrows enum class TrafficLight_TwoArrows:uint8_t
> {LeftArrow, RightArrow };
>
> 2. Motivation and scope
> Proposal could make more cleare code structure and decrease code
> overlapping and had writing
> 3. Design decisions
> It could be compiler extension
>
>
>
>
> BRG,
> Andrey
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
group enums together, but can't we do it already? Like:
enum class base_enum{red, Violet, blue};
Struct base{
using Type= base_enum;
};
enum class derived_enum{red, Violet, blue};
Struct derived:base{
using Type= base_enum;
};
This would allow you to pass derived where base is expected and use the
Type of derived. Inheriting enumerators on the other hand would not be a
good idea since you are mixing enums instead of group them.
On Mon, 20 Apr 2026, 3:47 pm Andrey Fokin via Std-Proposals, <
std-proposals_at_[hidden]> wrote:
> Title: Pxxxx: Add inheritance for Enum Class enumerations
> Author: Andrey Fokin, lazzyfox_at_[hidden]
> Date: 2026-04-20
> Project: Programming Language C++, Library Working Group
> Abstract: New inheritance feature to enum class (scoped enumerations)
> 1. Introduction
> According my experience the are situations when scped enumerations could
> be presented in OOP style – base enumeration type and some ancestors of.
> For example – we have to define a list of colors for traffic lights device.
> Is simple case we have just three colors and our enum could looks like
> enum class TrafficLight:uint8_t { Red, Yellow, Green };
> And probably this enum will cover biggest part of cases. But if we need to
> have a case wit Trafficligt wit left, rgih or two arrows we need ot use
> three diffeerent data types for each with big part of duplicated data in
> eatch.
> Case 1- additional letf arrow enum class TrafficLight_LefatArrow:uint8_t {
> Red, Yellow, Green, LeftArrow };
> Case 2- additional right arrow enum class TrafficLight_RightArrow:uint8_t
> { Red, Yellow, Green, RightArrow };
> Case 3- two additional arrows enum class TrafficLight_TwoArrows:uint8_t {
> Red, Yellow, Green, LeftArrow, RightArrow };
>
> In case of inheritance could be possible use as first case as a base class
> and athers as inherited to exclude overlapping data duplication and casese
> above cold looks like
> Case 4- additional letf arrow enum class TrafficLight:LefatArrow:uint8_t
> {LeftArrow };
> Case 5- additional right arrow enum class TrafficLight:RightArrow:uint8_t
> {RightArrow };
> Case 6- two additional arrows enum class TrafficLight_TwoArrows:uint8_t
> {LeftArrow, RightArrow };
>
> 2. Motivation and scope
> Proposal could make more cleare code structure and decrease code
> overlapping and had writing
> 3. Design decisions
> It could be compiler extension
>
>
>
>
> BRG,
> Andrey
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2026-04-20 11:00:42
