Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) inheritance

 

Inheritance is a technique to re-use methods of a class.

 

struct BaseClass //A base class
{
  virtual void SayHello();
};

struct DerivedClass : public BaseClass //A derived class, public inheritance
{
  //DerivedClass inherits SayHello method
  void SayBye();
};

 

There are three modes of inheritance:

  1. public inheritance, an 'is-a-kind-of' relationship, the most commonly used mode of inheritance
  2. protected inheritance, an obscure type of relationship
  3. private inheritance, an 'is-implemented-in-terms-of' relationship [1]

 

 

 

 

 

External links

 

 

 

 

 

 

References

 

  1. Scott Meyers. Effective C++ (3rd edition).ISBN:0-321-33487-6. Item 39: 'Use private inheritance judiciously'

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict