Syntax of C++ Inheritance
The core of using C++ inheritance is the colon that follows the name of the derived class. It denotes the place for the name of the base class and for the description of the mode of inheritance—public, private, or protected.
Listing 13.4 shows the same program as in Listing 13.3 but is implemented with the use of inheritance. The client code is the extension of the client code in Listing 13.3. This is why the output of this program (shown in Figure 13-3) is the extension of the output of the program in Listing 13.3.
Code Listing 13.4. Example of inheritance hierarchy for Account classes.
#include <iostream> using namespace std; class Account { // base class of hierarchy protected: double balance; public: Account(double ... |
Get Core C++ A Software Engineering Approach 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.