title: Using child class as a template parameter of a base class and as a nested name specifier
body: <p>I'm using my class as a template parameter of one of its parent class, and that parent class uses it in a template argument (though sizeof()). </p>
  
  <p>And the compiler gives me: </p>
  
  <blockquote>
    <p>error : incomplete type 'Invoker::workerClass {aka MyClass}' used in nested name specifier</p>
  </blockquote>
  
  <p>Yet the class is well defined in the file. I guess this is because the child class isn't instantiated at the moment of the base class' instantiation, yet that kind of thing happens with <a href="http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern" rel="noreferrer">CRTP</a> and there's no problems.</p>
  
  <p>The reason I use the child class in the template argument is to do a different function call if the child class has, or doesn't have, a specific function.</p>
  
  <p>Here's a minimal code for testing</p>
  
  <pre><code>/* Structure similar to boost's enable if, to use
    SFINAE */
  template &lt;int X=0, class U = void&gt;
  struct test {
      typedef U type;
  };
  
  enum Commands {
      Swim,
      Fly
  };
  
  /* Structure used for template overloading,
    as no partial function template specialization available */
  template&lt;Commands T&gt;
  struct Param {
  
  };
  
  template &lt;class T&gt;
  class Invoker
  {
  public:
      typedef T workerClass;
  
      workerClass *wc() {
          return static_cast&lt;workerClass*&gt;(this);
      }
  
      template &lt;Commands command&gt;
      void invoke() {
          invoke2(Param&lt;command&gt;());
      }
  
      /* If the child class has those functions, call them */
      /* Needs template paramter Y to apply SFINAE */
      template&lt;class Y=int&gt;
      typename test&lt;sizeof(Y)+sizeof(decltype(&amp;workerClass::fly))&gt;::type 
      invoke2(Param&lt;Fly&gt;) {
          wc()-&gt;fly();
      }
  
      template&lt;class Y=int&gt;
      typename test&lt;sizeof(Y)+sizeof(decltype(&amp;workerClass::swim))&gt;::type 
      invoke2(Param&lt;Swim&gt;) {
          wc()-&gt;shoot();
      }
  
      template&lt;Commands command&gt;
      void invoke2(Param&lt;command&gt;) {
          /* Default action */
          printf("Default handler for command %d\n", command);
      }
  };
  
  template &lt;class T, class Inv = Invoker&lt;T&gt; &gt;
  class BaseClass : public Inv
  {
  public:
      template&lt;Commands command&gt;
      void invoke() {
          Inv::template invoke&lt;command&gt;();
      }
  };
  
  class MyClass : public BaseClass&lt;MyClass&gt;
  {
  public:
      void swim() {
          printf("Swimming like a fish!\n");
      }
  
      /* void fly(); */
  };
  
  
  void testing() {
      MyClass foo;
      foo.invoke&lt;Fly&gt;(); /* No 'void fly()' in MyClass, calls the default handler */
      foo.invoke&lt;Swim&gt;(); /* Should print the swimming message */
  }
  </code></pre>
  
  <p>The error happens at the line:</p>
  
  <pre><code>typename test&lt;sizeof(Y)+sizeof(decltype(&amp;workerClass::fly))&gt;::type 
  </code></pre>
  
  <p>So, is there any compiler that supports this, or is this explicitely specified by the standard as an invalid use of templates? Do I have to change the way I'm doing this and find a way around? CRTP is giving me hope the code might be valid, but I'm not sure.</p>
  
  <p>If this really isn't possible, then why exactly, and why does CRTP work?</p>