Possible Duplicate:
Does std::list::remove method call destructor of each removed element?
Assume I have this:
void f(...)
{
.
.
std::list<X*> xList;
.
// Then i fill the list
std::list<X*>::iterator iter;
for (iter = xList.begin(); iter != xList.end(); ++iter)
{
*iter = new X();
}
}
When xList goes out of scope, I know that the container should call the destructor of the objects that are contained within the list? First, is that true?
If so, then since the list contains pointers to class X shouldn't the destructor ofX be called when xList goes out of scope? Thus freeing any memory that was held by X?