title: c++ casting base class to derived class mess
body: <p>If I were to create a base class called <code>base</code> and derived classes called <code>derived_1</code>, <code>derived_2</code> etc... I use a collection of instances of the base class, then when I retrieved an element and tried to use it I would find that C++ thinks it's type is that of the base class, probably because I retrieved it from a <code>std::vector</code> of base. Which is a problem when I want to use features that only exist for the specific derived class who's type I knew this object was when I put it into the vector.</p>
  
  <p>So I cast the element into the type it is supposed to be and found this wouldn't work.</p>
  
  <pre><code>(derived_3)obj_to_be_fixed;
  </code></pre>
  
  <p>And remembered that it's a pointer thing. After some tweaking this now worked.</p>
  
  <pre><code>*((derived_3*)&amp;obj_to_be_fixed);
  </code></pre>
  
  <p>Is this right or is there for example an <code>abc_cast()</code> function that does it with less mess?</p>
  
  <p>edit:</p>
  
  <p>I had to expand this into another question, the full solutions are shown there. <a href="https://stackoverflow.com/questions/4639703/why-the-polymorphic-types-error-and-cleanup-question">stackoverflow.com ... why-the-polymorphic-types-error-and-cleanup-question</a></p>