title: Upcasting pointers
body: <p>I have a doubt with upcasting with pointers in C++.</p>
  
  <p>I'm going to write an example of my problem:</p>
  
  <pre><code>class A {}
  class B : public A {}
  
  A* pA = new A();
  B* pB = new B();
  
  pA = pB; //fails
  pA = dynamic_cast&lt;A*&gt;(pB); //fails
  </code></pre>
  
  <p>I don't know what I'm missing. I think I don't understand at all the upcasting. Any help please? Thanks</p>
  
  <p>UPDATED With the error:</p>
  
  <pre><code>[exec] ..\asdf\qwerty.cpp(123) : error C2681: 'B*' : invalid expression type for dynamic_cast
  </code></pre>
  
  <p>I have found how it works, like this:</p>
  
  <pre><code>pA* = (pA*)pB; 
  </code></pre>
  
  <p>But I don't understand why.</p>
  
  <p>EDIT: My editor is telling me that: "a value of type B* cannot be assigned to an entity of type A*". What does this mean?</p>
  
  <p>To be more exactly, pB is being returned by a function. I don't know if it has something to do: is like this:</p>
  
  <pre><code>class C { 
      B* pB;
      B* getB() { return pB; }
  }
  
  A* pA;
  pA = c.getB(); //this crashes. c was declared before... it is just an example
  </code></pre>