title: c++ vector with inheritance
body: <p>Reference code:</p>
  
  <pre><code>#include &lt;vector&gt;
  #include &lt;iostream&gt;
  
  class Func {
  public:
      virtual void call() {
          std::cout&lt;&lt; "Func -&gt; call()" &lt;&lt; std::endl;
      }
  };
  
  class Foo : public Func {
  public:
      void call() {
          std::cout&lt;&lt; "Foo -&gt; call()" &lt;&lt; std::endl;
      }
  };
  
  class Bar : public Func {
  public:
      void call() {
          std::cout&lt;&lt; "Bar -&gt; call()" &lt;&lt; std::endl;
      }
  };
  
  int main(int argc, char** argv) {
      std::vector&lt;Func&gt; functors;
  
      functors.push_back( Func() );
      functors.push_back( Foo() );
      functors.push_back( Bar() );
  
      std::vector&lt;Func&gt;::iterator iter;
      for (iter = functors.begin(); iter != functors.end(); ++iter)
          (*iter).call();
  }
  </code></pre>
  
  <p>When run that code, it produces the following output on my computer:</p>
  
  <pre><code>$ ./test
  Func -&gt; call()
  Func -&gt; call()
  Func -&gt; call()
  </code></pre>
  
  <p>Would there be any way to ensure that the correct virtual function is called in this instance? I'm new at C++ but my best guess is that here:</p>
  
  <pre><code>(*iter).call();
  </code></pre>
  
  <p>It's being cast to a <code>Func</code> object. Is this correct?</p>