title: why Curiously Recurring Template Pattern (CRTP) works
body: <p>I meet a lot of explanations about what CRTP is, but there is no explanation of why it works.</p>
  
  <blockquote>
    <p>The Microsoft Implementation of CRTP in ATL was independently discovered, also in 1995 by Jan Falkin who accidentally derived a base class from a derived class. Christian Beaumont, first saw Jan's code and initially thought it couldn't possibly compile in the Microsoft compiler available at the time. Following this revelation that it did indeed did work, Christian based the entire ATL and WTL design on this mistake.</p>
  </blockquote>
  
  <p>For example, </p>
  
  <pre><code> template&lt; typename T &gt;
   class Base
   {
      ...
   };
  
   class Derived : public Base&lt; Derived &gt;
   {
      ...
   };
  </code></pre>
  
  <p>I understand why and when it could be used. But I want to know how the compiler works in this way. Because in my head it shouldn't work due to endless recursion: class <code>Derived</code> inherits from <code>Base&lt; Derived &gt;</code>, where <code>Derived</code> is class which inherits from <code>Base&lt; Derived &gt;</code>, where <code>Derived</code>... and so on.</p>
  
  <p>Could you please kindly explain step by step how it works from the compiler point of view?</p>