O'Reilly logo

SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required