title: Assign return value from function to a reference c++?
body: <p>This is a two part question.  Is it ok to assign the return value of a function to a reference?  Such as </p>
  
  <pre><code>Foo FuncBar()
  {
      return Foo();
  }
  
  // some where else
  Foo &amp;myFoo = FuncBar();
  </code></pre>
  
  <p>Is this ok?  Its my understanding that <code>FuncBar()</code> returns a Foo object and now <code>myFoo</code> is a reference to it.</p>
  
  <p>Second part of the question.  Is this an optimization?  So if your doing it in a loop a lot of the time is it better to do</p>
  
  <pre><code>Foo &amp;myFoo = FuncBar();
  </code></pre>
  
  <p>or</p>
  
  <pre><code>Foo myFoo = FuncBar();
  </code></pre>
  
  <p>And take into account the variables use, won't using the ref require slower dereferences?</p>