title: Need explanation on this code with polymorphism
body: <p>I stumbled uppon this code and I am quite confused on how it compiles since one of the function from A refers to static B.  Also what it's suppose to do.</p>
  
  <p>where B is derived from A.</p>
  
  <p>In A.h file</p>
  
  <pre><code>static A*   instance();
  </code></pre>
  
  <p>in B.h</p>
  
  <pre><code>static B* instance() { return dynamic_cast&lt;B*&gt;(A::instance()); }
  </code></pre>
  
  <p>in B.cpp</p>
  
  <pre><code>A* A::instance()
  {
      static B s_instance;
      return &amp;s_instance;
  }
  </code></pre>
  
  <p>Class definitions and such were omitted to lighten the code.</p>