The previous Exploration introduced general OOP principles. Now it’s time to see how to apply those principles to C++.
Deriving a Class
Defining a derived class is just like defining any other class, except that you include a base class access level and name after a colon. See Listing
38-1 for an example of some simple classes to support a library. Every item in the library is a work of some kind: a book, a magazine, a movie, and so on. To keep things simple, the class
work has only two derived classes,
book and
periodical.
import <iostream>;
import <string>;
import <string_view>;
class work
{
public:
work() ...