As was discussed earlier (see Chapter 2 in the BGL book), there are two major approaches to polymorphism in programming: parametric polymorphism and subtype polymorphism. C++ supports parametric polymorphism with templates and subtype polymorphism with class inheritance and dynamic binding of virtual member functions. Chapter 13 of Accelerated C++ is a thorough discussion of the mechanisms and uses of subtype polymorphism. The authors develop an example base class called Core and a derived class called Grad, for processing student records consisting of names and grades. Again, the issues of proper definition of constructors, assignment operators, and destructors come into play, in addition to the new issues of inheritance and virtual functions. |