title: Adding virtual functions without modifying the original classes
body: <p>Let's say we already have a hierarchy of classes, e.g.</p>
  
  <pre><code>class Shape { virtual void get_area() = 0; };
  class Square : Shape { ... };
  class Circle : Shape { ... };
  etc.
  </code></pre>
  
  <p>Now let's say that I want to (effectively) add a <code>virtual draw() = 0</code> method to <code>Shape</code> with appropriate definitions in each sub-class. <em>However</em>, let's say I want to do this without modifying those classes (as they are part of a library that I don't want to change).</p>
  
  <p>What would be the best way to go about this?</p>
  
  <p>Whether or not I actually "add" a <code>virtual</code> method or not is not important, I just want polymorphic behaviour given an array of pointers.</p>
  
  <p>My first thought would be to do this:</p>
  
  <pre><code>class IDrawable { virtual void draw() = 0; };
  class DrawableSquare : Square, IDrawable { void draw() { ... } };
  class DrawableCircle : Circle, IDrawable { void draw() { ... } };
  </code></pre>
  
  <p>and then just replace all creations of <code>Square</code>s and <code>Circle</code>s with <code>DrawableSquare</code>s and <code>DrawableCircle</code>s, respectively.</p>
  
  <p>Is that the best way to accomplish this, or is there something better (preferably something that leaves the creation of <code>Square</code>s and <code>Circle</code>s intact).</p>
  
  <p>Thanks in advance.</p>