Newbie STL question
I''m making my first foray into the STL, and I have a quick question about the list template (well all the templates really). Basically, do I need to call an erase member function on them before quitting my app, or will the class''s destructor handle that for me? I noticed that list, for example, has clear() which wipes out everything in the linked list, but do I have to call this when I''m exiting, or is that just for convenience if I want to clear out the list during execution?
Thanks,
Anthracks
Not being really familiar with the STL myself, I risk telling you the wrong thing, but common sense suggests that the destructor will destroy any memory associated with the list. Therefore, you should not need to call clear() or whatever yourself when your program exits.
War Worlds - A 3D Real-Time Strategy game in development.
War Worlds - A 3D Real-Time Strategy game in development.
That is correct, a container will destroy all contained elements. However, be very careful: if you are storing pointers in your list that have been dynamically allocated, you have to free that memory yourself.
This is typical of one of my apps:
Hope that''s clear. BTW, my funky ''for'' formatting is so that the auto-indenting looks decent in MSVC. Also BTW, there''s a more elegant way to do those deletes at the end using functors and "for_each", but that''s hardly a beginner topic. =)
This is typical of one of my apps:
|
Hope that''s clear. BTW, my funky ''for'' formatting is so that the auto-indenting looks decent in MSVC. Also BTW, there''s a more elegant way to do those deletes at the end using functors and "for_each", but that''s hardly a beginner topic. =)
is there a way to iterator through a container with a function with a parameter..
like with generate..
but then generate cant take a parameter..
is there a way to send in a parameter ???
{ Stating the obvious never helped any situation !! }
like with generate..
but then generate cant take a parameter..
|
is there a way to send in a parameter ???
{ Stating the obvious never helped any situation !! }
It appears I misspoke: for_each cannot alter the contained elements, so you can''t use it to delete everything. Bummer. Anybody know where this comes from?
jwalker: Can''t you construct the functor with arguments? I don''t know if that will accomplish what you want because I don''t know what you''re trying to do.
jwalker: Can''t you construct the functor with arguments? I don''t know if that will accomplish what you want because I don''t know what you''re trying to do.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement