title: Best way to return more specialized object
body: <p>I have a base class <code>Base</code> with multiple child classes, e.g <code>Child1</code>, <code>Child2</code> etc.
  Inside this <code>Base</code> class I have a method returning a pointer to <code>BaseDefinition</code>:</p>
  
  <pre><code>virtual std::shared_ptr&lt;BaseDefinition&gt; GetDefinition() { return m_def; }
  </code></pre>
  
  <p>Now parallel to the class tree of <code>Base</code>, the <code>BaseDefinition</code> class also have childs classes: <code>Child1Definiton</code>, <code>Child2Definition</code> etc. The <code>GetDefinition()</code> implementation of <code>Child1</code> will e.g return a <code>std::shared_ptr&lt;Child1Definition&gt;</code>.</p>
  
  <p>However the return type of <code>GetDefinition()</code> is of course a <code>std::shared_ptr&lt;BaseDefinition&gt;</code> and this is also completely right as long as we have <code>Base*</code> pointers. But suppose we have a more specialized pointer, e.g <code>Child1*</code>, in that case <code>Child1::GetDefinition()</code> should have a return type of <code>std::shared_ptr&lt;Child1Definition&gt;</code>. How can one achieve this behaviour? </p>