The real final, ultimate body class
void cube::identify(ostream &os)
os << "cube of length " << length
We make “traditional” member functions identify(ostream&) for our classes (which have nothing to do with the << operators)
void cylinder::identify(ostream &os)
os << "cylinder of radius " << radius
ostream& operator<< (ostream& os, cube &c)
ostream& operator<< (ostream& os, cylinder &c)
and we let the non-member operator<< functions call the (public) member functions; no problem here:
ostream& operator<< (ostream& os, body &b)
but now also body can easily have a operator<< non-member function which calls the proper member function and so gives the proper output.