<<< Constructing a derived class example     Index     Inheritance and friendship >>>

15. Access levels for inheritance


  • 
    class Derived : public Base
    
        // same as
        struct Derived : Base
    
    
  • Most common: all public members of Base are also public in Derived, so they can be used by everyone.

  • 
    class Derived : private Base
    
        // same as
        class Derived : Base
    
    
  • All public and protected members of Base become private within Derived, so they can be used only by members of Derived.

  • 
    class Derived : protected Base
    
    
  • All public and protected members of Base become protected within Derived, so they can only be used by members of Derived and members of classes derived from Derived.

  • All non-public inheritance is a suspect - have a good reason before doing it.


<<< Constructing a derived class example     Index     Inheritance and friendship >>>