### Examples of Derived Classes

    /************************************************************************
    *

You can refer to inherited members (base class members) as if they were members of the derived class:

                                                                            *
    ************************************************************************/

    // This example illustrates references
    // to base class members.

    class base
    {
    public:
          int a,b;
    };
    class derived : public base
    {
    public:
          int c;
    };
    void main()
    {
          derived d;
          d.a = 1;      // base::a
          d.b = 2;      // base::b
          d.c = 3;      // derived::c
    }

    /************************************************************************
    *

The derived class can also add new class members and redefine existing base class members. In the above example, the two inherited members , a and b, of the derived class d, in addition to the derived class member c, are assigned values.

For example:

                                                                            *
    ************************************************************************/

    // This example illustrates references to base class
    // members with the scope resolution (::) operator.

    #include <iostream.h>
    class base
    {
    public:
          char* name;
          void display(char* i) {cout << i << endl;}
    };
    class derived : public base
    {
    public:
          char* name;
          void display(char* i){cout << i << endl;}
    };
    void main()
    {
          derived d;                    // create derived class object
          d.name = "Derived Class";     // assignment to derived::name
          d.base::name = "Base Class";  // assignment to base::name

          // call derived::display(derived::name)
          d.display(d.name);

          // call base::display(base::name)
          d.base::display(d.base::name);
    }

    /************************************************************************
    *

In the following example, d, a pointer to a derived class object is assigned to bptr, a pointer to a base class object. A call is made to display() using bptr. Even though bptr has a type of pointer to base, in the body of display() the name member of derived is manipulated:

                                                                            *
    ************************************************************************/

    // This example illustrates how to make a pointer
    // to a derived class point to a base class.

    #include <iostream.h>
    class base
    {
    public:
          char* name;
          void display(char* i) {cout << i << endl;}
    };
    class derived : public base
    {
    public:
          char* name;
          void display(char* i){cout << i << endl;}
    };
    void main()
    {
          derived d;

          // standard conversion from derived* to base*
          base* bptr = &d;

          // call base::display(base::name)
          bptr->display(bptr->name);
    }