by gpu_explorer · 6y ago · 0 comments
class Object
{
int* data = new int[32];
void move_into( Object& object )
{
object.data = data;
data = nullptr;
}
~Object()
{
delete[] data;
}
}
Object a;
Object b;
a.move_into( b );
I think much of the confusion arises from wondering where is the allocation for int* data located? It's somewhere on the heap. What if the data member were int data[32] instead? What would the class look like? What would 'a' look like afterwards?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.