next up previous
Next: How do I avoid Up: class and struct Previous: How do I call

How do I derive classes?

The purpose of deriving classes is to factor code: if two classes derive from a parent class, the members defined in the parent will be accessible by both, and have to be coded only once. The level of access to a parent's member is specified with public, private and protected. The following examples show the three types of derivation and their effect.
class A
{
  /* ... */
};

//access to members of A are transmitted to B.
class B: public A
{
  /* ... */
};

//public members of A become protected members of C
class C: protected A 
{
  /* ... */
};

//public and protected members of A become private members of D
class D: private A
{
  /* ... */
};



Alexis Angelidis (PhD) 2005-01-11