title: Upcast and Downcast in C++
body: <pre><code>class file {
      std::string name;
  };
  
  class directory : public file {
      std::vector&lt;file*&gt; entries;
  };
  
  directory d;
  file f;
  
  f = d; // Only d.name is copied to f; entries are lost
  </code></pre>
  
  <p>Is it if we do this:</p>
  
  <pre><code>directory* dp = new directory;
  file* fp ;
  
  fp = dynamic_cast&lt;file*&gt;(dp); 
  </code></pre>
  
  <p>Keeps entries and identity as a directory object or still only <code>dp-&gt;name</code> is copied to <code>f</code>; entries are lost.</p>
  
  <hr>
  
  <p>Also, how does downcast work?</p>
  
  <p>What happens if we do:</p>
  
  <pre><code>dp = dynamic_cast&lt;dp*&gt; (fp);
  </code></pre>