title: friend function returning reference to private data member
body: <p>I have two questions about the following code.  </p>
  
  <pre><code>class cls{
      int vi;
      public:
          cls(int v=37) { vi=v; }
          friend int&amp; f(cls);
  };
  
  int&amp; f(cls c) { return c.vi; }
  
  int main(){
      const cls d(15);
      f(d)=8;
      cout&lt;&lt;f(d);
      return 0;
  }
  </code></pre>
  
  <ol>
  <li>Why does it compile, since f(d) = 8 attemps to modify a const object?</li>
  <li>Why does it still print 15, even after removing the const attribute?</li>
  </ol>