PDA

View Full Version : new e delete



mickey
17th July 2006, 14:58
hi do anyone wich is correct between two? thanks


std::vector <FancyPopup*> ppop;
for (int i=0; i<8; i++)
ppop.push_back(new FancyPopup(this));
for( std::vector <FancyPopup*>::iterator i = ppop.begin(); i != ppop.end(); ++i ) {
delete *i; //or delete [] *i;
}
ppop.clear();

wysota
17th July 2006, 15:11
You should use the same type of operator for releasing memory as you did for allocating it, so:
new -> delete
new [] -> delete []
malloc() -> free()

In your case it should be "delete *i";