Date: Wed, 1 Sep 2021 21:08:54 +0300
Hi, why is enum class inheritance not allowed? I have faced up a problem
that I need to extend the enum class for each system. However, there is no
good tool to do it in C++ as far as I know.
Let me explain more briefly, assume that there are more than one subsystems
that are using the same common base system. The common system contains such
as memory, time management controllers and these controllers consist of
two-part. One of them is a common one and the other one is
system-dependent. I want to keep their name and id in the enum class.
Although I can extend functionalities with inheritance, I cannot extend
their enums. To do this, I have two options. The first one is putting the
all enums same enum class or duplicate names for each sub-system. As you
guess, these solutions are not good solutions to remove dependencies or
duplications. As a reason for it, what about adding the inheritance for
enum classes?
Maybe it can be;
enum class CommonSystem {
T1,
T2,
T3,
};
enum class SubSystem : CommonSystem {
U1, // starts with T3 + 1
U2,
U3,
};
enum class <class name> : <underlying type>, <parent class...> {
};
Best Regards,
that I need to extend the enum class for each system. However, there is no
good tool to do it in C++ as far as I know.
Let me explain more briefly, assume that there are more than one subsystems
that are using the same common base system. The common system contains such
as memory, time management controllers and these controllers consist of
two-part. One of them is a common one and the other one is
system-dependent. I want to keep their name and id in the enum class.
Although I can extend functionalities with inheritance, I cannot extend
their enums. To do this, I have two options. The first one is putting the
all enums same enum class or duplicate names for each sub-system. As you
guess, these solutions are not good solutions to remove dependencies or
duplications. As a reason for it, what about adding the inheritance for
enum classes?
Maybe it can be;
enum class CommonSystem {
T1,
T2,
T3,
};
enum class SubSystem : CommonSystem {
U1, // starts with T3 + 1
U2,
U3,
};
enum class <class name> : <underlying type>, <parent class...> {
};
Best Regards,
-- Murat Hepeyiler 5G Software Engineer & C++ Developer www.linkedin.com/in/murathepeyiler
Received on 2021-09-01 13:09:34