Skip to main content
GameDev.net gamedev.net
🔒 Locked

Quick STL question

Started by brain21 Jul 19, 2003 at 2:46 AM 3 replies 300+ views
Original Post
brain21
brain21
Ok, check out this code:
#include <stl/list>

list< int* >TheList;

int *TheInt;

for ( int i = 0; i < 3; i++ )
{
  TheInt = new int;
  TheList.push_back( TheInt );
}

TheList.clear();

(Untested code) ok, when I call TheList.clear(), do the int pointers get deleted? I mean do the memory allocated using the "new" command get de-allocated or is that up to me? Denny
DigitalDelusion
DigitalDelusion
as posted above you''ll have to call delete yourself and here''s
a neat way to accomplish that in a very STL:ish way =)


struct delete_object
{
template <typename T>
void operator()(T *ptr){ delete ptr;}
};

//in your code

std::for_each( TheList.begin(), TheList.end(), delete_object());
TheList.clear();

HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
brain21
brain21
That look cool! thanks every one.

Denny

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.