Move value from local stack to heap? (C++)
How can I take an object-as-value result from a method call and place it on the heap? For instance: The Qt QImage::scaledToWidth method returns a copy of the QImage object. Right now I'm doing: QImage *new_img_on_heap = new QImage(old_imgage_on_heap->scaledToWidth(2000)); 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. The reason I want to put it on the heap is because the real QImage is large, and I want it to outlive the lifetime of the current method. I was intending to stuff a pointer to