Posted by John Kugelman on April 20, 2001 at 04:30:56:
In Reply to: Dynamic Memory question posted by David Shell on April 19, 2001 at 23:33:24:
The STL containers just store copies of the parameter type; they don't know anything about dynamic allocation or construction.
We're supposed to store pointers in the lists; the STL containers don't know anything about what type the pointers point to, and they don't care. When you manipulate the STL containers you're just manipulating pointers, not actual objects.
So the answer is, do it yourself. Create them dynamically with
new, store the pointers in the containers, and then
delete the pointers before the containers are destroyed.
Post a Followup