title: C++ template C2039
body: <p>This compiles:</p>
  
  <pre><code>template &lt;class T&gt;
  class Bar {};
  
  template&lt;class T, class Dummy=void&gt;
  class Foo;
  
  template&lt;class T&gt;
  class Foo &lt;T, typename std::enable_if&lt;
      std::is_base_of&lt;Bar&lt;T&gt;, T&gt;::value
  &gt;::type&gt; {
      public:
          //THIS CHANGES IN THE 2ND SNIPPET
          void test () const {
              std::cout &lt;&lt; "test";
          }
  };
  
  class Cat : Bar&lt;Cat&gt; {};
  
  int main () {
      Foo&lt;Cat&gt; foo;
      foo.test();
      return 0;
  }
  </code></pre>
  
  <p>This errors:</p>
  
  <pre><code>template &lt;class T&gt;
  class Bar {};
  
  template&lt;class T, class Dummy=void&gt;
  class Foo;
  
  template&lt;class T&gt;
  class Foo &lt;T, typename std::enable_if&lt;
      std::is_base_of&lt;Bar&lt;T&gt;, T&gt;::value
  &gt;::type&gt; {
      public:
          //THIS CHANGED!
          void test () const;
  };
  
  //THIS WAS ADDED SINCE THE 1ST SNIPPET!
  template&lt;class T&gt;
  void Foo&lt;T&gt;::test () const {
      std::cout &lt;&lt; "test";
  } //error C2039: 'test' : is not a member of 'Foo&lt;T&gt;'
  
  class Cat : Bar&lt;Cat&gt; {};
  
  int main () {
      Foo&lt;Cat&gt; foo;
      foo.test();
      return 0;
  }
  </code></pre>
  
  <p>I have marked the differences. <strong>Why does it error in the 2nd code snippet? How do I keep declaration and definition separate while avoiding the error?</strong></p>
  
  <p>I'm guessing it's got something to do with this:
  "template
  void Foo::test () const"</p>
  
  <p>Like, this is the wrong way to tell the compiler that the method <strong>test() const</strong> is a method of <strong>template class template class Foo , T>::value >::type></strong></p>
  
  <p>I've, of course, looked it up on Google and StackOverflow but it seems that, whenever this error pops up for templates, it's a different reason every time. (Probably because a lot of things can cause the C2039 error.)</p>
  
  <p>Also, could a mod. or someone help me add the <strong>C2039</strong> tag to this post? It says I need a min. of 1500 rep. to add that tag.</p>
  
  <p>-- Rambling --
  It also be noted that it's been a while since I've used C++; and even longer since I've used templates. I know this might be a weird way to use templates but I can assure you I have a valid reason!</p>