Referring to an Object as Its Class or Its Superclass

A look at the new main.cpp in Listing 22.3 shows that a reference to a superclass can refer to a descendant class as a result of inheritance.

Listing 22.3. main.cpp Using the New Classes
 *1: #include "PersistentTapeExternalInterfaceModule.h" 2: #include "AccumulatorModule.h" *3: #include "PersistentTapeModule.h" 4: #include "ControllerModule.h" 5: 6: int main(int argc, char* argv[]) 7: { *8: SAMSCalculator::aPersistentTapeExternalInterface ExternalInterface(argv[1]); 9: SAMSCalculator::anAccumulator Accumulator; *10: SAMSCalculator::aPersistentTape Tape(argv[1]); 11: *12: SAMSCalculator::aController Calculator *13: ( *14: ExternalInterface, *15: Accumulator, *16: Tape *17: ); 18: 19: return ...

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.