Friday, November 23, 2007

Deleting STL list pointers

list TestList;
list:: iterator Iter;

// Adding data to the
Iter = TestList.begin();
TestList.insert(new Test(),Iter);
Iter++;
TestList.insert(new Test(),Iter);


Test* pT = NULL;




//Removing All the pointers from the STL list as follows :


while( TestList.size() > 0)
{
Iter = TestList.begin();
pT = *Iter;
TestList.remove(pT); //Remove the item from the list
SAFE_DELETE(pT); //Free the resource
}

No comments: