Protected Access

As you've seen, a derived class cannot use member variables and functions declared in the private section of the superclass. But a superclass can offer functions and member variables that only the superclass and its derived classes can use, putting them in a special protected section.

The declaration of anExternalInterface in Listing 22.4 shows some of the changes needed to make it ready for inheritance, including placing two functions in the protected section so that they can be overridden by aPersistentTapeExternalInterface.

Listing 22.4. Protected Section in anExternalInterface
 1: #ifndef ExternalInterfaceModuleH 2: #define ExternalInterfaceModuleH 3: 4: #include "RequestModule.h" 5: 6: namespace SAMSCalculator 7: { 8: class ...

Get SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION 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.