title: static_pointer_cast<Derived> pReallyABase = static_pointer_cast<Derived>(pBase) works! Why?
body: <p>I don't understand why this works.
  pReallyABase is a downcasted shared_pointer&lt; Derived > which points to a base class instance.</p>
  
  <p>I understand why the compiler lets me call pReallyABase->onlyForDerived() since I defined it as a derived class pointer, but why don't I get a runtime error when I try to invoke a derived class function using that pointer?</p>
  
  <pre><code>class Base { 
      public:
          virtual string whatAmI() {
              return "I am a Base";
          }
  };
  
  class Derived : public Base {
      public:
          virtual string whatAmI() {
              return "I am a Derived";
          }
  
          string onlyForDerived() {
              return "I can do Derived things";
          }
  };
  
  
  int main(int argc, char *argv[]) { 
      shared_ptr&lt;Base&gt; pBase = shared_ptr&lt;Base&gt;(new Base);
      shared_ptr&lt;Derived&gt; pReallyABase = static_pointer_cast&lt;Derived&gt;(pBase);
  
      cout &lt;&lt; pReallyABase-&gt;whatAmI() &lt;&lt; endl;
      cout &lt;&lt; pReallyABase-&gt;onlyForDerived() &lt;&lt; endl;  //Why does this work?
      return 0;
  }
  </code></pre>
  
  <h3>Results</h3>
  
  <pre><code>I am a Base
  I can do Derived things
  </code></pre>