Chapter 10. Pretty Poly

By the end of the previous chapter, we had created a DatedStockItem class by inheritance from the StockItem class, adding an expiration date field. This was a fine solution to the problem of creating a new class based on the existing StockItem class without rewriting all of the already functioning code in that class. Unfortunately, however, it didn't allow us to mix objects of the original StockItem class in the same vector with those of the new DatedStockItem class and still have the correct Reorder function called for the derived class object. So far, we've been using the first two major organizing principles of object-oriented programming: encapsulation and inheritance. Now our requirement of mixing base and derived ...

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.