Chapter 48: | How To Make one Class a Friend of Another Class |
In Chapter 47, you learned about the definition of two classes,
header
and link
, that enable you to construct lists of
railroad_car
objects. So that you did not have to deal with too
much complexity at once, all member variables and member functions in those
two classes are in the public portion of the class definitions, where they
are too freely accessible.
Of course, add
, advance
, access
, endp
,
reset
and the header
constructor are used in the train
program and therefore should be in the public portion of the header
class. In this chapter, you learn how to make all other member variables
and member functions inaccessible, except through those six functions,
which constitute the public interface. Along the way, you learn about
friends and why they are needed.