3 ms·
In this example no because of pointer. Where is the allocation for int* data located? It's not inside the object. You can think easily of the state of 'a' after
by gpu_explorer 7y ago
In this example no because of pointer. Where is the allocation for int* data located? It's not inside the object. You can think easily of the state of 'a' after calling move_into.
But maybe with int data[32] as a data member this is harder to reason about.
This is a way to illustrate move semantics and confusion behind what happens to the 'moved from' object.
- AnimalMuppet 7y agoYou made the moved-to pointer point to the moved-from allocated heap data. Now nothing points to the heap data that was initially allocated by the moved-to object. So if you don't delete[] the moved-to data pointer, then you leaked 32 bytes of heap.
- gpu_explorer 7y agoWhat happens when the program exits?
- AnimalMuppet 7y agoThen it doesn't matter. It matters if you run out of heap before the program exits, though.