title: CRTP to avoid virtual member function overhead
body: <p>In <a href="https://stackoverflow.com/questions/262254/c-crtp-to-avoid-dynamic-polymorphism">CRTP to avoid dynamic polymorphism</a>, the following solution is proposed to avoid the overhead of virtual member functions and impose a specific interface:</p>
  
  <pre><code>template &lt;class Derived&gt;
  struct base {
    void foo() {
      static_cast&lt;Derived *&gt;(this)-&gt;foo();
    };
  };
  
  struct my_type : base&lt;my_type&gt; {
    void foo() {}; // required to compile. &lt; Don't see why
  };
  
  struct your_type : base&lt;your_type&gt; {
    void foo() {}; // required to compile. &lt; Don't see why
  };
  </code></pre>
  
  <p>However it seems that the derived class does not require a definition to compile as it inherits one (the code compiles fine without defining a my_type::foo). In fact if a function is provided, the base function will not be called when using the derived class.</p>
  
  <p>So the question is, is the following code replacement acceptable (and standard?):</p>
  
  <pre><code>template &lt;class Derived&gt;
  struct base {
    void foo() {
      // Generate a meaningful error if called
      (void)sizeof( Derived::foo_IS_MISSING );
    };
  };
  
  struct my_type : base&lt;my_type&gt; {
    void foo() {}; // required to compile.
  };
  
  struct your_type : base&lt;your_type&gt; {
    void foo() {}; // required to compile.
  };
  
  int main() {
    my_type my_obj;
    my_obj.foo(); // will fail if foo missing in derived class
  }
  </code></pre>