brucew@caen.engin.umich.edu (Bruce Hugh Wilson) (03/29/91)
I'm writing an application which involves inputting/saving/reading (from a keyboard and text file) objects of different classes, but with a common parent class. It's easy enough to write various overloaded << operators to handle objects of different classes- but this is because the operators can recognize the class the object belongs to. A sample file output might look like: <motor> motor1, 3.4, 5.4, .001 ... <load> load1, 4.3 <shaft> big_shaft,10.8,0.1 ... Is there a way to avoid the use of a switch statement in reading this info in? My current strategy entails reading <the_identifier> and using a switch statement, creating an object of the appropriate class, and then reading in the next line of the file. Is there a simpler/better way?