title: Inherited classes in a C++11 priority queue
body: <p>I'm new to OOP in C++ and I'm not sure if this will work but I'd like to have multiple class types in a C++ std priority queue. </p>
  
  <p>I set the classes up so that they all inherit from a base class and then use the base class to make all the functions, I just don't know how to make everything call the child class functions though. At the moment when I call the <code>foo()</code> function it calls the parent function rather than the child function </p>
  
  <p>Is there a way to cast back without explicitly knowing what type it is? I'll have several different child classes which will do different things not just the single one shown.</p>
  
  <p>The output of the code is currently <code>Parent</code> when I would have guessed it was <code>Child</code>.</p>
  
  <p>I have a feeling I'm doing something wrong with the <code>virtual</code> keyword, should <code>foo()</code> be a purely virtual function?</p>
  
  <p><strong>Parent.h</strong></p>
  
  <pre><code>#pragma once
  class Parent{
      public:
          virtual ~Parent(){};
          virtual std::string foo() const { return "Parent"; }
  };
  </code></pre>
  
  <p><strong>Child.h</strong></p>
  
  <pre><code>#pragma once
  #include &lt;iostream&gt;
  #include "Parent.h"
  class Child: public Parent{
      public:
          Child();
          ~Child();
          std::string foo() const;
  };
  </code></pre>
  
  <p><strong>Child.cpp</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "Parent.h"
  #include "Child.h"
  
  Child::Child(){}
  Child::~Child(){}
  std::string Child::foo() const{ return "Child"; }
  </code></pre>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;queue&gt;
  #include "Parent.h"
  #include "Child.h"
  using namespace std;
  
  //Fake compare function for compilation, real one calls a compare method
  class comparefunction{
      public:
          bool operator()( const Parent&amp; p1, const Parent&amp; p2) const{
              return true;
          }
  };
  
  int main(){
      priority_queue&lt;Parent, vector&lt;Parent&gt;, comparefunction&gt; pq;
      Child c;
  
      pq.push(c);
  
      cout &lt;&lt; pq.top().foo() &lt;&lt; endl;
      pq.pop();
  }
  </code></pre>