title: Move value from local stack to heap? (C++)
body: <p>How can I take an object-as-value result from a method call and place it on the heap?</p>
  
  <p>For instance:</p>
  
  <p>The Qt <a href="https://doc.qt.io/qt-5/qimage.html#scaledToWidth" rel="noreferrer"><code>QImage::scaledToWidth</code> method</a> returns a copy of the <code>QImage</code> object.   </p>
  
  <p>Right now I'm doing:</p>
  
  <pre><code>QImage *new_img_on_heap = new QImage(old_imgage_on_heap-&gt;scaledToWidth(2000));
  </code></pre>
  
  <p>Is this the only way?  Seems like it's going through the trouble of making a 3rd whole new object when I already have a perfect good one on the stack.</p>
  
  <p>The reason I want to put it on the heap is because the real <code>QImage</code> is large, and I want it to outlive the lifetime of the current method.  I was intending to stuff a pointer to it in a field of my class.</p>
  
  <p>I know that <code>QImage</code> has some sort of implicit data sharing, but I'm not exactly clear on how it works under the hood. Plus, I wanted to know a general solution should I ever need to use objects not as well designed as Qt's.</p>