class Circle: public Shape {
public: .....
private: int radius;// radius of circle
};
Thus radius is in addition to the colour and originmembers
that it inherits from Shape.
When one class is derived from another, then C++ allows a
base pointer to point to an instance of a derived class:For
example a variable of type Shape*can point to a Circle,
SquareorTriangleobject.
Circle c;
Shape* p = &c;
// define a circle
// p points to a Circle
Thus a parameter of type Shape*can match any actual
argument that points to a derived member. Although it
appears that the following function requires a Shape
argument, it can in fact receive a Circle, Squareor
Triangle.
void add_to_list (Shape&s)
{ ......
} Thus add_to_listis a highly versatile function that can
handle differ kinds of shape arguments.