Unfortunately, this is not possible in C ++ 14. I hope we have such a language function in C ++ 17. Since you already have several workarounds for your problem, I will not offer a solution.
I would like to point out that the wording should be an “extension” and not an “inheritance”. An extension allows more values (since you go from 3 to 6 values in your example), while inheritance means adding more restrictions to a given base class, so the set of features is compressed. Therefore, potential casting will work exactly the opposite of inheritance. You can distinguish a derived class from a base class, and not vice versa, with class inheritance. But when you have extensions, you should be able to apply the base class to its extension, and not vice versa. I say “must” because, as I said, such a language function still does not exist.
Ogњen Shobaјiћ Sep 18 '14 at 21:49 2014-09-18 21:49
source share