I have a question regarding to STL std::list objects.
Let we have a definition of own structure:
Then we create some global std:list object:
Also we have a function to add objects into that list:
My question is simple and regards to removing the objects from the list:
void AddObject(LPSTR lpstrFile, DWORD dwSize, BOOL bFlag)
MYSTRUCT* pMySrtuct = new MYSTRUCT;
pMySrtuct->strFile = lpstrFile;
pMySrtuct->dwSize = dwSize;
pMySrtuct->bFlag = bFlag;
The question is:
std::list<MYSTRUCT*>::iterator itr = g_MyStructList.begin();
while(itr != g_MyStructList.end())
delete *itr; // is it necessary to delete the iterator or may be g_MyStructList.remove will do that?
itr = g_MyStructList.begin();
Does g_MyStructList.remove will only remove the object from the list or it also will free the memory dinamically allocated for MYSTRUCT object in AddObject function?
Also if the answer is NO (it does not delete the object, it just removes the object from the list and we must delete the iterator ourself), what should be the first: removing from the list or delete?
Thank you for the answers.