title: Polymorphism and Pointers (C++)
body: <p>Say the class B inherits from class A and class A contains a virtual function</p>
  
  <pre><code>virtual public foo() {cout&lt;&lt;"I'm A"&lt;&lt; endl';}
  </code></pre>
  
  <p>while B contains </p>
  
  <pre><code>public foo() {cout&lt;&lt;"I'm B" &lt;&lt; endl';}
  </code></pre>
  
  <p>Why is it that</p>
  
  <pre><code>A* x = new B;
  </code></pre>
  
  <p>will let x use the function foo() where it prints out "I'm B", but</p>
  
  <pre><code>A x = B;
  </code></pre>
  
  <p>would give me the other function? </p>