In C ++ there is no such thing as a "common class". You have a template , and the template is not a class. Rather, template instances become classes. However, these are completely different, separate, and unrelated classes, so Derived<A> and Derived<B> have nothing to do with each other.
In addition, what you do is beautiful. In any instance of the Derived<T> template, T is the actual class (suppose it is actually a class, not, say, an array or int ), and you can extract from it.
source share