Jump to content
  • Advertisement
Sign in to follow this  
kingpinzs

How to delete the complete list

This topic is 4136 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If DataList2 is the std::list wont the fallowing code delete all of it? Because I am trying and it does not seam to be doing the trick. DataList2.erase (DataList2.begin(), DataList2.end());

Share this post


Link to post
Share on other sites
Advertisement
It should. However, use the member function clear to clear the entire list instead of using the function taking an arbitrary iterator range.

Share this post


Link to post
Share on other sites
As above, use clear().

Note that if the type contained with the list is a pointer, then delete will not be called on the pointers. The list cleans up what it allocates; you must clean up what you allocate.

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie

Note that if the type contained with the list is a pointer, then delete will not be called on the pointers. The list cleans up what it allocates; you must clean up what you allocate.


How would I do that?

Share this post


Link to post
Share on other sites
Quote:
Original post by kingpinzs
How would I do that?
Iterate through the container, and delete each element.


std::list <Type *> Data;

for(std::list <Type *> ::iterator iIndex = Data.begin(), iTail = Data.end(); iIndex != iTail; ++ iIndex)
delete * iIndex;

Data.clear();


Share this post


Link to post
Share on other sites
Quote:
Original post by kingpinzs
Is there another way to delete it with out using a pointer?
I'm not sure I understand what you mean. You only have to manually do what's outlined above if your container stores pointers in the first place.

Share this post


Link to post
Share on other sites
I belive that this delete * iIndex; means a pointer to iIndex but I am not sure though. I tryed just delete iIndex it gave me error
type `struct std::_List_iterator<int>' argument given to `delete', expected pointer

Share this post


Link to post
Share on other sites
You need to dereference the iterator to properly delete your data. In other words, "delete * iIndex" is what you should be using.

Share this post


Link to post
Share on other sites
in this function

void Add(POINT pos,RECT Src)
{

paddle.Pos=pos;

paddle.Src=Src;

Sprites.push_back(paddle);

}

how could I remove pos and src instead of adding it?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!