Advanced C++ Topics
Inheritance Virtual methods and late binding Friend classes and methods Class templates Overloaded operators Iterators
EECS 268 Programming II 1
Inheritance Revisited
Inheritance is useful to
explicitly represent relationships among program components reuse as much design and implementation effort as possible avoid parallel implementations that are error prone since they are hard to keep synchronized
Class hierarchies represent shared and distinct relationships between classes
derived (sub) class inherits base (super) class properties
all member data and functions except constructors and destructors
2
Inheritance Basic Concepts
Superclass or base class
a class from which another class is derived
Subclass, derived class, or descendant class
a class that inherits all members of another class can add new members to those it inherits can redefine an inherited method of its base class, if the two methods have the same parameter declarations
EECS 268 Programming II 3
Inheritance Basic Concepts
An instance of the base class An instance of the derived class
members (except constructors and destructor)
An instance of a derived class has all the behaviors of
- data and methods directly by name
EECS 268 Programming II 4