The right place to create the new character bufferand assign it to the
serial_number
pointeris inside a one-argument constructor. The
following engine
class definition exhibits such a constructor:
class engine { public: engine ( ) { } // New constructor: engine (char *input_buffer) { // Create new array just long enough: serial_number = new char[strlen(input_buffer) + 1]; ... } virtual char* short_name ( ) {return "eng";} };
Thus, the new engine
constructor arranges for the serial_number
member variable, declared in the railroad_car
class, to point to the
first character in a new character array.