title: In C++, How 'a pointer point to a parent intance' can be casted to 'a child type'?
body: <pre><code>class CParent {
  public:
      void Output() {
          cout &lt;&lt; &quot;I'm Parent!&quot; &lt;&lt; endl;
      }
  
      virtual void VirtualOutput() {
          cout &lt;&lt; &quot;I'm Parent!&quot; &lt;&lt; endl;
      }
  };
  
  class CChild : public CParent {
  public:
      void Output() {
          cout &lt;&lt; &quot;I'm Child!&quot; &lt;&lt; endl;
      }
  
      void VirtualOutput() {
          cout &lt;&lt; &quot;I'm Child!&quot; &lt;&lt; endl;
      }
  };
  
  class CChildChild : public CChild {
  public:
      void Output() {
          cout &lt;&lt; &quot;I'm ChildChild!&quot; &lt;&lt; endl;
      }
  
      void VirtualOutput() {
          cout &lt;&lt; &quot;I'm ChildChild!&quot; &lt;&lt; endl;
      }
  
      void CChildOnly() {
          cout &lt;&lt; &quot;I'm only on ChildChild!&quot; &lt;&lt; endl;
      }
  };
  
  int main() {
      CParent     cp;
      CChild      cc;
      CChildChild ccc;
  
      CParent* pCP1 = &amp;cp;
      CParent* pCP2 = &amp;cc;
      CParent* pCP3 = &amp;ccc;
  
      ((CChildChild*)pCP1)-&gt;CChildOnly();  //&lt;-this code actually works. HOW? WHY?
  
      return 0;
  }
  </code></pre>
  <p>The pointer variable 'pCP1' is pointing 'cp' which is 'an object of CParent'. So the 'down casting' doesn't make any sense according to what I've learned.</p>
  <p>But it works and shows 'I'm only on ChildChild!' with no problem.</p>
  <p>The 'cp' has only 'CParent part' on its memory construct. So it can not be 'down casted' as far as I know.</p>
  <p>But it works. How?</p>