How can I provide printing for an entire hierarchy rooted at “class X”?
Provide a friend operator<< that calls a protected virtual function: class X { protected: virtual void print(ostream& o) const; //or "=0;" if "X" is abstract public: friend ostream& operator<<(ostream& o,const X& x) {x.print(o); return o;} //... }; Now all subclasses of X merely provide their own "print(ostream&)const" member function, and they all share the common "<<" operator. Friends don't bind dynamically, but this technique makes them *act* as if they were.