Inheritance: Derivation Lists
In C++ Inheritance is commonly called Class Derivation
. It is implemented using two extensions to the syntax:
derivation list (a list of parent classes)
protected data members and member functions
Derivation List
- It follows the class name
- Consists of a ":" followed by a comma separated list of
base classes
- The public qualifier on a base class indicates
public derivation:
- This form of derivation is used most frequently.
Public derivation implies that public members of the base class
will be inherited as public members of the derived class.
- The protected access specifier used with members of a class
specifies that these members may only be accessed by member functions of
the class or member functions of its derived class.
Example...
- protected members of the base class are inherited as
protected members of the derived class.
- Private members of the base class, although contained in the
derived class, are private to the base class, and therefore, cannot be
accessed by member functions of the derived class. They can only be
accessed by member functions of the base class.
class DerivedClassName : public BaseClassOne, public BaseClassTwo{
public:
// Public members go here
protected:
// Protected members go here
private:
// Private members go here
};
Sample Programs ...
The protected qualifier on a base class indicates
protected derivation:
- Protected derivation implies that public members of the base class
will be inherited as protected members of the derived class, and
protected members of the base class will be inherited as
protected members of the derived class.
- Private members of the base class, although contained in the
derived class, are private to the base class, and therefore, cannot be
accessed by member functions of the derived class. They can only be
accessed by member functions of the base class.
The private qualifier on a base class indicates
private derivation:
- The default form of derivation is private derivation.
Private derivation implies that public and protected
members of the base class will be inherited as private members
of the derived class.
- Private members of the base class, although contained in the
derived class, are private to the base class, and therefore, cannot be
accessed by member functions of the derived class. They can only be
accessed by member functions of the base class.
- Sample Programs ...
Summary of Inheritance Types and Access
Levels
Back to Previous Page
Document:
Last Modified On: