list dog;
………….
…………
So I added many dog objects to it.
If I call dog.pop_front();
Does memory automatically gets deallocated ? For the object that I popped out ?
So If I call
list<Dog*> dog2;
dog2.push_back(dog.front());
and then I will call dog.pop_front() So this will work? I will assume Dog as type struct.
You keep asking about this sequence:
At time1, both
dog2anddoghave a pointer to the same object.At time2, the pointer to that object is removed from
dogand is only indog2.Assuming you originally created that object with
new Dog, the object will not be freed until you explicitly free it by callingdelete ptr