title: Cannot access private member from a template friend function
body: <p>Here is an example of my code:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;memory&gt;
  
  class Base
  {
  public:
    virtual void name() = 0;
  };
  
  using ptr_t = std::unique_ptr&lt;Base&gt;;
  
  class A : public Base
  {
    A(int x) : n(x) {}
  
  public:
    void name() override
    {
      std::cout &lt;&lt; "Test " &lt;&lt; n &lt;&lt; "\n";
    }
  
    template &lt;typename T&gt;
    friend ptr_t create(int x);
  
  private:
    int n;
  };
  
  template &lt;typename T&gt;
  ptr_t create(int x)
  {
    return std::make_unique&lt;T&gt;(x);
  }
  
  int main()
  {
    auto a = create&lt;A&gt;(3);
    a-&gt;name();
  }
  </code></pre>
  
  <p>At first I thought the problem was in the conversion from <code>std::unique_ptr&lt;A&gt;</code> to <code>std::unique_ptr&lt;Base&gt;</code>. But that seems to work fine in an isolated code sample and is also correct according to this answer:
  <a href="https://stackoverflow.com/questions/17473900/unique-ptr-to-a-base-class">unique_ptr to a base class</a> </p>
  
  <p>The code above also works if I use a raw pointer instead of a unique pointer.</p>
  
  <p>Can someone explain what I'm missing. Thank you.</p>