title: C++ Returning Reference to New Object
body: <p>I know there are similar questions to this but none of them give a definitive answer to my question...</p>
  
  <p>Are both these okay in terms of best practices? Or should I be returning a pointer?
  And if not how should they be changed to follow best practices.</p>
  
  <p>I want to return a reference to a new object from a function. My implementation is as follow:</p>
  
  <pre><code>MyClass&amp; doSomething() {
     return *(new MyClass());
  }
  
  MyClass a = doSomething();
  </code></pre>
  
  <p>Is this okay because a new instance of MyClass is being allocated on the heap with new?</p>
  
  <p>Or should I be making it constant (I'm not really sure when to do this or not)?</p>
  
  <pre><code>const MyClass&amp; doSomething() {
      return *(new MyClass());
  }
  </code></pre>
  
  <p>And if both these are wrong should I just be returning a pointer to the new object?</p>
  
  <p>Thanks.</p>