title: Friend function not working
body: <p>In the following code I am trying to have a friend function access the private member of the class.  To my understanding I am correctly declaring it as a friend function, but VS2012 is giving me the error:</p>
  
  <pre><code>error C2248: 'X::S::s_' : cannot access private member declared in class 'X::S'
  </code></pre>
  
  <p>Can anyone suggest what I am doing wrong?  This is the simplest example that demonstrates the compiler error that I could come up with.</p>
  
  <pre><code>namespace X
  {
      class S
      {
          friend std::string r(X::S &amp;s);
          std::unique_ptr&lt;std::istream&gt; s_;
      };
  }
  std::string r(X::S &amp;s)
  {
      auto&amp; x = s.s_;
      return "";
  }
  </code></pre>