title: Two questions about casting objects in cpp
body: <p><strong><em>Question A</em></strong></p>
  
  <p>If I have two classes: "father", and "MyClassa" and I want to do this:</p>
  
  <pre><code>father* a;
  MyClassa b;
  a = &amp;b;
  ((MyClassa *)a) - &gt; b();
  </code></pre>
  
  <p>I can do the casting like in the sample above (<code>b()</code> is a function belonging to <code>MyClassa</code> class and not found in <code>father</code> class).</p>
  
  <p>But when I do this:</p>
  
  <pre><code>father* a;
  MyClassa b;
  a = &amp;b;
  a = ((MyClassa *)a);
  a-&gt;b();
  </code></pre>
  
  <p>It doesnt work for me and tells me that he <code>b()</code> function not exist in that class (like the casting didn't work). </p>
  
  <p>What are the differences between these two code samples actually and what is causing this differences?</p>
  
  <p><strong><em>Question B</em></strong></p>
  
  <p>When I use 'dynamic_cast' to cast a father to be a child like this:</p>
  
  <pre><code>Father * fp= new Father;
  Child * cp = dynamic_cast&lt;Child *&gt; fp;
  </code></pre>
  
  <p>It returns me a '0' value to the pointer.
  But when I do the same with reference:</p>
  
  <pre><code>Father &amp; fp= new Father;
  Child &amp; cp = dynamic_cast&lt;Child &amp;&gt; fp;
  </code></pre>
  
  <p>It raises an error 'bad casting'.</p>
  
  <p>Why is there a difference?</p>