I’m curious about the ways of printing user-defined objects. By that, I mean printing objects to an output stream. Is it possible to have a stream class provide methods that could print all kinds of objects, similar to how the Object type in Java can provide toString() methods to all derived classes? I imagine that one issue is the lack of classes being able to derive from the stream class, since with the Object example in Java, all classes are implicitly subclasses of Object. Are there others?
I’m curious about the ways of printing user-defined objects. By that, I mean printing
Share
Override the
toString()function and call that. I don’t see how you could have a god class that simply prints all kinds of objects.