title: Specialize member function template of a class template
body: <p>I have the following code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  template&lt;int A&gt;
  class Thing
  { // 5
      public:
          Thing() :
              data(A) {
          }
  
          template&lt;int B&gt;
          Thing &amp;operator=(const Thing&lt;B&gt; &amp;other) {
              printf("operator=: A = %d; B = %d\n", A, B);
              printf("this-&gt;data = %d\n", data);
          }
  
      private:
          int data;
  };
  
  int main() {
      Thing&lt;0&gt; a, b;
      Thing&lt;1&gt; c;
  
      a = b;
      a = c;
      c = b;
  
      return 0;
  }
  </code></pre>
  
  <p>I need to specialize <code>Thing&lt;A&gt;::operator=</code> for <code>A == B</code>.  I have tried this:</p>
  
  <pre><code>template&lt;int B&gt;
  template&lt;int A&gt;
  Thing&lt;A&gt; &amp;Thing&lt;A&gt;::template operator=(const Thing&lt;A&gt; &amp;other) { // 23
      printf("operator= (specialized): A = %d; B = %d; A %c= B\n", A, B, (A == B) ? '=' : '!');
      printf("this-&gt;data = %d; other.data = %d\n", data, other.data);
  }
  </code></pre>
  
  <p>However, I receive compile errors with g++:</p>
  
  <pre><code>23: error: invalid use of incomplete type ‘class Thing&lt;B&gt;’
   5: error: declaration of ‘class Thing&lt;B&gt;’
  </code></pre>
  
  <p>I have tried using an <code>if(A == B)</code> in <code>operator=</code> without a specialization.  However, I receive errors for accessing the private member <code>data</code>, which I need to access where <code>A == B</code>.</p>
  
  <p>How can I properly specialize my member function template <code>operator=</code> of the class template <code>Thing</code>?</p>