![]() |
![]() |
![]() |
![]() |
![]() |
|
To decide which volume member function to use on, say, a
box_car object, the C++ compiler searches up from the
box_car object, through the subclasssuperclass chain, to find the
first member function named volume. For the box_car example,
the only volume member function that the C++ compiler finds is the
one found in the box class.
On the other hand, the volume member function selected by the C++
compiler to work on gondola_car objects is the one found in the
gondola_car class, and the volume member function found in
the box class is said to be
shadowed by that lower-level
member function.
Of course, if you happen to have a box object that is neither a box
car nor a gondola car, and you want to compute the volume of that
box object, then the volume member function found in the
box class is the one that C++ selects for you.