title: Iterating through a vector of abstract classes
body: <p>I have the following classes.  An error occurs during the for loop in the <code>Main</code> class.  The compiler complains about the <code>draw</code> function "is of non-type GLCommand".  The idea of the application is to store many different types of <code>GLCommand</code> and <code>Shape</code> within the same vector.  Should I take a different design approach, or is their a simple fix to this problem?</p>
  
  <p>Interface:</p>
  
  <pre><code>class GLCommand
  {
      public:
          GLCommand();
          virtual ~GLCommand();
      virtual void draw() = 0;
  };
  </code></pre>
  
  <p>Abstract Class:</p>
  
  <pre><code>class Shape : public GLCommand
  {
  public:
    Shape(int);
    virtual ~Shape();
    virtual void draw() {};
  private:
    double colour[];
    int sides;
  
  };
  </code></pre>
  
  <p>Derived class:</p>
  
  <pre><code>class Polygon : public Shape
  {
    public:
      Polygon(int sides);
      virtual ~Polygon();
  
      void draw();
  
  private:
    vector&lt;Coordinates *&gt; verticies;
  
  };
  </code></pre>
  
  <p>Main:</p>
  
  <pre><code>int main()
  {
      vector &lt;GLCommand*&gt; vec;
      Polygon p(4);
  
      vec.push_back(&amp;p);
  
      for (vector&lt;GLCommand*&gt;::iterator it = vec.begin(); it!=vec.end(); ++it)
      {
        *it-&gt;draw();
      }
      return 0;
  }
  </code></pre>