Listing 3 The shape hierarchy with rectangle and triangle derived from abstract base class polygon

class shape
   {
public:
   ...
   virtual shape *clone() const = 0;
   ...
   };

...

class circle : public shape
   {
public:
   shape *clone() const;
   ...
   };
   
shape *circle::clone() const
   {
   return new circle(*this);
   }
   
...

class polygon : public shape
   {
public:
//  shape *clone() const = 0;  // still pure
   ...
   };
   
...

class rectangle : public polygon
   {
public:
   shape *clone() const;
   ...
   };
   
shape *rectangle::clone() const
   {
   return new rectangle(*this);
   }
   
...

class triangle : public polygon
   {
public:
   shape *clone() const;
   ...
   };

shape *triangle::clone() const
   {
   return new triangle(*this);
   }
   
...

// End of File