title: Lifecyle of a returned class constructor call
body: <p>Here is my code:</p>
  <pre><code>class Value{
  public:
  int x;
  Value(int y):x(y){
      
      }
  };
  
  
  Value getVal(){
    return Value(2);
  }
  
  int main() {
  
  
  const Value &amp; rec = getVal();
  return 0;
  }
  </code></pre>
  <p>My questions:</p>
  <ol>
  <li><p>Is it safe to do this <code>return Value(2);</code> ?</p>
  <p>Does the created object expire once the functions ends ?
  If it does then how to properly receive it?</p>
  </li>
  <li><p>Why do I need to declare <code>const</code> if I am making a reference variable like on my example?</p>
  </li>
  </ol>