Home Segments Index Top Previous Next

554: Mainline

To tell the C++ compiler that a parameter is to be a call-by-reference parameter, you add an ampersand, &, to the parameter's type indicator.

For example, in the ordinary_capacity_function, you tell the C++ compiler that r is to be a call-by-reference parameter as follows:

        Tell C++ that the parameter is to be --* 
        a call-by-reference parameter          | 
                                               v 
double ordinary_capacity_function (railroad_car& r) { 
  return r.capacity ( ); 
} 

With this one-character amendment, the ordinary_capacity_function works fine. The analyze_train program displays the following report, as it should:

eng     0 
box     2880 
box     2880 
tnk     1130.97 
cab     0