Home Segments Index Top Previous Next

540: Mainline

Thus, there is no such data type as a string. When you hand over a string to a function, you supply a character pointer that points to the first character in that string. When you want to return a string from a function, you really ask for a pointer to the first character in that string.

For example, when you define the short_name function in the railroad_car class, you declare that it is to return a character pointer as follows:

virtual char* short_name ( ) {return "rrc";}     // For railroad_car 

Similarly, the following defines a short_name function for the box_car class definition:

virtual char* short_name ( ) {return "box";}     // For box_car 

Thus, both short_name functions return character pointers.