I have a base class Base
, that a lot of other classes will be derived from. I would like to define:
template<typename Derived>
ostream &operator<< (ostream &o, Derived &derived) {
}
But only for classes derived from Base
. I need all previously defined operator<<
to be used for other types. How to do that? Is that possible?
I cannot create ostream &operator<< (ostream &o, Base &base)
, because I need the exact type to be used in some type traits. Is there any way to "push" the derived type while passing the value as a base type?