title: Questions about static_cast
body: <p>I've wrote a piece of code, but I am confused with its output:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class B{
  public:
      virtual void foo() {cout &lt;&lt; "B::foo" &lt;&lt; endl;}
  };
  
  class D:public B{
  public:
      virtual void foo() {cout &lt;&lt; "D::foo" &lt;&lt; endl;}
      void disp() {cout &lt;&lt; "D::disp" &lt;&lt; endl;}
  };
  
  void func(B *pb){
      D *pd1 = static_cast&lt;D*&gt;(pb);
      pd1-&gt;foo();
      pd1-&gt;disp();
  }
  
  int main(int argc, char *argv[])
  {
  
      B* pb = new B();
      func(pb); 
  
      return 0;
  }
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>B::foo
  D::disp
  </code></pre>
  
  <p>But as far as I know, <code>pb</code> points to type B. And there's no function named <code>disp()</code> in it? So, why could it get access to <code>disp()</code> function in class D?</p>