PDA

View Full Version : How to inheriting a enum type?



ricardodovalle
26th February 2014, 16:25
Anyone knows a alternative to inheriting a enum and add more constants inside derived class?
Is it possible and it will work with switch and if?

Thanks

stampede
26th February 2014, 19:04
There is no way to directly inherit an enum in C++.
But you can create a simple workaround:


class MyEnumBase{
public:
enum{
Symbol1,
Symbol2
};
};

class MyEnumDerived : public MyEnumBase{
public:
enum{
Symbol3 = Symbol2+1,
Symbol4
};
};