In the following program, box_car_volume
is redefined, yet again,
albeit awkwardly, to illustrate the limited availability of parameter
values:
#include// Define multiplier and box_car_volume first: double multiplier ( ) { return h * w * l; // BUG! } double box_car_volume (double h, double w, double l) { return multiplier ( ); } // Then, define main: main ( ) { cout << "The volume of the box car is " << box_car_volume (10.5, 9.5, 40.0) << endl; cout << "The value of the parameters are " << h << ", " << w << ", and " << l // BUG! << endl; }
In this program, box_car_volume
asks multiplier
a function
with no parametersto perform the actual computation of h * w * l
.
However, the C++ compiler cannot compile multiplier
, because no
values for the h
, w
, or l
parameters of
box_car_volume
are available to multiplier
.
Moreover, C++ cannot compile the second output statement in the
main
function. The reason is that h
, w
, and l
exist only during the execution of the function in which they appear as
parameters; h
, w
, and l
no longer exist once that
function has returned.