How do I implement abstract classes in C++ while allowing for subclass method calls?
<p>I made a class called <code>A</code> that has a virtual method <code>do_something</code>:</p>

<pre><code>class A {
  virtual int do_something() = 0;
}
</code></pre>

<p><code>B</code> subclasses <code>A</code>:</p>

<pre><code>class B {
  virtual int do_something() {
    return 42;
  }
}
</code></pre>

<p>Somewhere in my main function, I do this.</p>

<pre><code>vector&lt;A&gt; arr;
arr.push_back(B());
int val = arr[0].do_something();
</code></pre>

<p>However, I get a compiler error complaining that <code>do_something</code> is a pure virtual function. I believe this is because I declared the vector to contain objects of type <code>A</code>, and <code>A</code> is an abstract class. The compiler thus doesn't know to look in class <code>B</code> to see if <code>do_something</code> is define.</p>

<p>Is there a way around this? Can I still store a vector of objects of different types (with a common superclass though that declares a common virtual function)?</p>
