Home Segments Index Top Previous Next

455: Mainline

Of course, you could define a display_short_name function for railroad_car in which rrc is an acronym for railroad cars:

class railroad_car { 
  public: railroad_car ( ) { } 
          void display_short_name ( ) {cout << "rrc";} 
}; 

Including such a definition gets you past the C++ compiler, but then, you find the result peculiar:

rrc 
rrc 
rrc 
rrc 
rrc 

The reason you get nothing but lines containing rrc is that C++ ordinarily decides which display_short_name function to use at compile time, and at compile time, all C++ knows is that it is looking at an array that is supposed to contain railroad_car objects.