title: How to declare member template of class template as friend?
body: <p>Given the following code:</p>
  <pre class="lang-cpp prettyprint-override"><code>template &lt;typename T, typename D&gt; class B;
  
  template &lt;typename T&gt;
  class A {
  public:
    A() { }
    template &lt;typename D&gt;
    A(B&lt;T, D&gt;);
  };
  
  template &lt;typename T, typename D&gt;
  class B {
    friend A&lt;T&gt;::A(B&lt;T, D&gt;);
    int x;
  };
  
  template &lt;typename T&gt;
  template &lt;typename D&gt;
  A&lt;T&gt;::A(B&lt;T, D&gt; b) {
    b.x = 42;
  }
  
  int main() {
    B&lt;int, double&gt; b;
    A&lt;int&gt; a(b);
    return 0;
  }
  </code></pre>
  <p>I want to declare member template <code>A(B&lt;T, D&gt;)</code> of class template <code>A&lt;T&gt;</code> as friend.</p>
  <p>So I declared, <code>friend A&lt;T&gt;::A(B&lt;T, D&gt;);</code></p>
  <p>But I got a compile error:</p>
  <pre><code>test.cc: In instantiation of ‘class B&lt;int, double&gt;’:
  test.cc:24:18:   required from here
  test.cc:13:10: error: prototype for ‘A&lt;int&gt;::A(B&lt;int, double&gt;)’ does not match any in class ‘A&lt;int&gt;’
     friend A&lt;T&gt;::A(B&lt;T, D&gt;);
            ^~~~
  test.cc:4:7: error: candidates are: constexpr A&lt;int&gt;::A(A&lt;int&gt;&amp;&amp;)
   class A {
         ^
  test.cc:4:7: error:                 constexpr A&lt;int&gt;::A(const A&lt;int&gt;&amp;)
  test.cc:8:3: error:                 template&lt;class D&gt; A&lt;T&gt;::A(B&lt;T, D&gt;) [with D = D; T = int]
     A(B&lt;T, D&gt;);
     ^
  test.cc:6:3: error:                 A&lt;T&gt;::A() [with T = int]
     A() { }
     ^
  test.cc: In instantiation of ‘A&lt;T&gt;::A(B&lt;T, D&gt;) [with D = double; T = int]’:
  test.cc:25:13:   required from here
  test.cc:20:5: error: ‘int B&lt;int, double&gt;::x’ is private within this context
     b.x = 42;
     ~~^
  test.cc:14:7: note: declared private here
     int x;
         ^
  </code></pre>
  <p>How to fix it?</p>