Inheritance

Inheritance

RECALL: Objects as Members of Classes

Inheritance - not same as objects as members

Syntax

  • In general - most restrictive access used
    • Protected - also accessible by member functions and member functions of a "derived" class
    • Constructor initializer must add on the
      : base_cls_name(var_list)
      after the cls_name::cls_name
      class HourlyWorker :public Employee
      {
      ...
      };
    • Can call base class functions - use ::
      Base-class :: base-fn();

    Inherited Access Restrictions
    Base Class Member Derived Class Access Derived Class Member
    private : private inaccessible
    protected : private private
    public : private private
        
    private : public inaccessible
    protected : public protected
    public : public public
        
    private : protected inaccessible
    protected : protected protected
    public : protected protected

    Simple and Multiple Inheritance