As you recall from the last chapter, this is very important when using virtual functions, the pointer must point to the base class. The pointers that will be stored in this array will all point to objects of the derived classes however. When we use the resulting pointers to refer to the methods, the system will choose the method at run time, not at compile time as nearly all of our other programs have been doing. This is true dynamic binding because if we were to change the values of some of the pointers in the array, we would then call different methods with the same pointers. In order for this to work, the interface had to be identical for each function, but the implementation could be different for each function.
Polymorphism consists of two root words, poly and morph.
Poly means different and refers to the implementation, and morph means the same which refers to the interface. Be sure to compile and execute this program before continuing on in this chapter. You will recall that the linking step requires you to combine several files in order to satisfy all system calls. After you have done that, we will use the same objects in another way to show how they can be reused. The two classes were put in the same file because they work together so closely and neither is of much value without the other.