title: declare template friend function of template class
body: <p>I have a class template <code>Obj</code> and a function template <code>make_obj</code>.  <code>Obj</code> has a <code>private</code> single constructor defined, which takes a reference to its templated type to bind to.</p>
  
  <pre><code>template &lt;typename T&gt;
  class Obj {
    private:
      T&amp; t;
      Obj(T&amp; t)
          : t{t}
      { }
  };
  
  template &lt;typename T&gt;
  Obj&lt;T&gt; make_obj(T&amp; t) { 
      return {t};
  }
  </code></pre>
  
  <p>What I want is to declare the <code>make_obj</code> function a <code>friend</code> so that it can create <code>Obj</code>'s, but no one else can (except via the copy ctor).</p>
  
  <hr>
  
  <p>I have tried several friend declaration including</p>
  
  <pre><code>friend Obj make_obj(T&amp;);
  </code></pre>
  
  <p>and </p>
  
  <pre><code>template &lt;typename T1, typename T2&gt;
  friend Obj&lt;T1&gt; make_obj(T2&amp;);
  </code></pre>
  
  <p>The latter being a less than desirable attempt at making all template instantiations of <code>make_obj</code> friends of the <code>Obj</code> class.  However in both of these cases I get the same error:</p>
  
  <pre><code>error: calling a private constructor of class 'Obj&lt;char const[6]&gt;'
      return {t};
             ^
  
  note: in instantiation of function template specialization
        'make_obj&lt;const char *&gt;' requested here
      auto s = make_obj("hello");
               ^
  </code></pre>
  
  <p>trying to do <code>make_obj("hello");</code> for example purposes.</p>
  
  <p>How can I allow only <code>make_obj</code> access to <code>Obj</code>'s value contructor?</p>