Home Segments Index Top Previous Next

664: Mainline

The reason for introducing check_owner is to have a believable function in hand with a class-object, call-by-value parameter. Now that you have it, note that a railroad_car object is copied whenever check_owner is called, because the parameter is a call-by-value parameter:

Memory reserved for                      Memory reserved for r, 
railroad_car argument                    the railroad_car parameter 
 |                                        | 
 v                                        v 
*-----*               Copy               *-----* 
|     |          ------------->          |     | 
|-----|                                  |-----| 
|     |                                  |     | 
|-----|                                  |-----| 
|     |                                  |     | 
|-----|                                  *-----* 
|     | | 
|-----| | 
|     | | Subclass-specific portion not copied 
|-----| |  
|     | | 
*-----*   

As you know, only the railroad-car portion of the object is copied, inasmuch as the parameter is declared to be a railroad-car parameter. In this particular situation, only the railroad-car portion is needed, however.