'Does std::list's erase member function call the destructor for all stored elements?
I am debugging one memory issue it has some relation with the std::list::erase method.
While reading the documentation for std::list::erase, I saw this statement:
"This effectively reduces the container size by the number of elements removed, which are destroyed."
I am having difficulty in understanding this statement. As an example, consider this setup:
class demo {
};
std::list<demo *> mylist;
Now, suppose I call mylist.erase(iterator of list). I thought that this would call the destructor for class demo, but it doesn't seem to, which seems to contradict the statement "which are destroyed."
Can you please help me with this?
Thanks!
Solution 1:[1]
And just to clarify, erase() also destroys the element in the same way that clear() does.
// Removes the element from the list and destroys it:
mylist.erase(iterator);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | A Lundgren |
