From -3981192826942615185
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,1c452393d407b15c
X-Google-Attributes: gidf78e5,public
From: James Kuyper <kuyper@wizard.net>
Subject: Re: removing list elements
Date: 1999/03/16
Message-ID: <36EDA9E7.AB9BDE03@wizard.net>#1/1
X-Deja-AN: 455518811
X-NNTP-Posting-Host: 209.8.153.33
Content-Transfer-Encoding: 7bit
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <7cj8nk$tmk$1@nnrp1.dejanews.com>
Content-Type: text/plain; charset=us-ascii
X-Trace: news6.ispnews.com 921545032 209.8.153.33 (Mon, 15 Mar 1999 19:43:52 EDT)
Organization: Not Enough
Mime-Version: 1.0
NNTP-Posting-Date: Mon, 15 Mar 1999 19:43:52 EDT
Newsgroups: comp.std.c++
Originator: clamage@taumet


alexxandra@my-dejanews.com wrote:
> 
> This problem has been described to me by a fellow developer, and I cannot find
> much insight online or in books.  Using the STL list, we wanted to substitute
> our home-grown implementation of a linked list.  However, we were storing
> (pointers or references to) objects in the linked list and we've run into a
> problem with the code dumping core from the stl section.  Should I assume it
> is the developer's responsibility to remove the object when objects and not
> straight data are being stored in the list?  If so, would a reasonable
> solution be to overload list's remove() to call the destructor on the object
> being removed?

Standard containers don't pay any attention to what objects they actuall
contain; they don't see the difference between an integer and a pointer,
and they treat them both the same; which is NOT what you want. If you
are allocating memory, and putting pointers to that memory in a standard
container, you have to make sure to deallocate the memory yourself
before allowing the container to delete the memory the pointer is stored
in.

You can't store references in an standard container; the contained
objects must be CopyConstructible, and references don't qualify.


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




