title: How come a non-const reference cannot bind to a temporary object?
body: <p>Why is it not allowed to get non-const reference to a temporary object, 
  which function <code>getx()</code> returns? Clearly, this is prohibited by C++ Standard 
  but I am interested in the purpose of such restriction, <strong>not a reference</strong> to the standard. </p>
  
  <pre><code>struct X
  {
      X&amp; ref() { return *this; }
  };
  
  X getx() { return X();}
  
  void g(X &amp; x) {}    
  
  int f()
  {
      const X&amp; x = getx(); // OK
      X&amp; x = getx(); // error
      X&amp; x = getx().ref(); // OK
      g(getx()); //error
      g(getx().ref()); //OK
      return 0;
  }
  </code></pre>
  
  <ol>
  <li>It is clear that the lifetime of the object cannot be the cause, because 
  constant reference to an object is <em>not prohibited</em> by C++ Standard.</li>
  <li>It is clear that the temporary object is not constant in the sample above, because calls to non-constant functions are permitted. For instance, <code>ref()</code> could modify the temporary object.  </li>
  <li>In addition, <code>ref()</code> allows you to fool the compiler and get a link to this temporary object and that solves our problem.</li>
  </ol>
  
  <p><strong>In addition:</strong></p>
  
  <p>They say "assigning a temporary object to the const reference extends the lifetime of this object" and " Nothing is said about non-const references though". 
  My <strong>additional question</strong>. Does following assignment extend the lifetime of temporary object?</p>
  
  <pre><code>X&amp; x = getx().ref(); // OK
  </code></pre>