Polymorphism

To select the correct function to be called based on the actual type of an object at run time, we have to use polymorphism. Polymorphic behavior of our StockItem and DatedStockItem classes means that we can (for example) mix StockItem and DatedStockItem objects in a vector and have the right Reorder function executed for each object in the vector.

Susan had a question about the relationship between base and derived classes:

Susan: What do the base and derived classes share besides an interface?

Steve: The derived class contains all of the member variables of the base class and can call any of the member functions of the base class. Of course, the derived class can also add whatever new member functions and member variables it ...

Get Learning to Program in C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.