title: How to define a template member function of a template class
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5108359/how-do-i-define-a-template-function-within-a-template-class-outside-of-the-class">How do I define a template function within a template class outside of the class definition?</a>  </p>
  </blockquote>
  
  
  
  <p>I'm struggling with the syntax for the case where I have a template member function within a template class:</p>
  
  <pre><code>template &lt;typename T&gt; class Foo
  {
      void Bar(const T * t);
      template &lt;typename T2&gt; void Bar(const T2 * t);
  };
  
  template &lt;typename T&gt; void Foo&lt;T&gt;::Bar(const T * t)
  {
      // ... no problem ...
  }
  
  template &lt;typename T&gt; void Foo&lt;T&gt;::Bar&lt;typename T2&gt;(const T2 * t)
  {
      // ... this is where I'm tearing my hair out ...
  }
  </code></pre>
  
  <p>The first member function is fine, but the template member function which handles types other than the base type of the template class is where I am having problems. For the above case I get the following errors:</p>
  
  <pre><code>template_problem.cpp:12: error: parse error in template argument list
  template_problem.cpp:12: error: expected ‘,’ or ‘...’ before ‘*’ token
  template_problem.cpp:12: error: ISO C++ forbids declaration of ‘T2’ with no type
  template_problem.cpp:12: error: template-id ‘Bar&lt;&lt;expression error&gt; &gt;’ in declaration of primary template
  template_problem.cpp:12: error: prototype for ‘void Foo&lt;T&gt;::Bar(int)’ does not match any in class ‘Foo&lt;T&gt;’
  template_problem.cpp:4: error: candidates are: template&lt;class T&gt; template&lt;class T2&gt; void Foo::Bar(const T2*)
  template_problem.cpp:7: error:                 void Foo&lt;T&gt;::Bar(const T*)
  template_problem.cpp:12: error: template definition of non-template ‘void Foo&lt;T&gt;::Bar(int)’
  </code></pre>
  
  <p>and I've also tried every other syntax variation I can think of for the template version of <code>Bar</code>.</p>