title: Store return value of function in reference C++
body: <p>Is it valid to store the return value of an object in a reference?</p>
  
  <pre><code>class A { ... };
  A myFunction()
  {
      A myObject;
      return myObject;
  } //myObject goes out of scope here
  
  void mySecondFunction()
  {
      A&amp; mySecondObject = myFunction();
  }
  </code></pre>
  
  <p>Is it possible to do this in order to avoid copying myObject to mySecondObject? myObject is not needed anymore and should be exactly the same as mySecondObject so it would in theory be faster just to pass ownership of the object from one object to another. (This is also possible using boost shared pointer but that has the overhead of the shared pointer.)</p>
  
  <p>Thanks in advance.</p>