473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

STL: delete needed along with erase?

Hi all.

I have a list of pointers to a complicated object. When I erase() a
member of that list, the little blob of memory that contains the
pointer is deleted, I think. But the object pointed to is not
deleted, true? It is not an auto_ptr or any kind of wrapped
pointer.

Further, I assume that the iterator I am holding is no longer valid
once I delete the element. I can't safely erase the member first,
then delete the object through the iterator. So the sequence ought to
be: 1. Delete the object. 2. Erase the list element.

I am checking my understanding, because the code I am working on,
which I inherited, doesn't delete the object at all, either before or
after the element is erased.
Abraham

Jul 9 '07 #1
3 1725
Ab********************@yahoo.com wrote:
I have a list of pointers to a complicated object. When I erase() a
member of that list, the little blob of memory that contains the
pointer is deleted, I think.
Whatever the implementation does to get rid of it, yes.
But the object pointed to is not
deleted, true?
True.
It is not an auto_ptr or any kind of wrapped
pointer.
Right. You cannot use 'auto_ptr', but 'shared_ptr' should be fine.
Further, I assume that the iterator I am holding is no longer valid
once I delete the element.
You mean, once you *erase* it? "Delete" has a particular meaning in
C++, as you know. Yes, the iterator is invalid if you erase the list
element behind it.
I can't safely erase the member first,
then delete the object through the iterator. So the sequence ought to
be: 1. Delete the object. 2. Erase the list element.
That sounds right.
I am checking my understanding, because the code I am working on,
which I inherited, doesn't delete the object at all, either before or
after the element is erased.
Good thinking.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 9 '07 #2
Thanks, Victor.

That's what I needed to know.
Abraham
On Jul 9, 9:22 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
AbrahamLincolnIllin...@yahoo.com wrote:
I have a list of pointers to a complicated object. When I erase() a
member of that list, the little blob of memory that contains the
pointer is deleted, I think.

Whatever the implementation does to get rid of it, yes.
: :
Jul 9 '07 #3
Ab********************@yahoo.com wrote:
Thanks, Victor.
Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or the group FAQ list:
<http://www.parashift.com/c++-faq-lite/how-to-post.html>
Jul 9 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Paras | last post by:
Hi What is the correct way to delete an element from STL list while iterating through the list list<A*> _ls; A * a; list<A*>::iterator si1;
20
by: Hanzo | last post by:
I'm iterating over a vector of base class pointers and deleting those which meet a certain criteria...i'm using pretty text-book code for the particular delete/erasure (it's straight out of Myers'...
3
by: Kenneth Massey | last post by:
Is the following code guaranteed to work? I have a hashed set of pointers, which I would like to selectively delete from. Can I iterate through the set, deleting certain ones, without...
0
by: Tony Johansson | last post by:
Hello! I have two classes called Handle which is a template class and a class Integer which is not a template class. The Integer class is just a wrapper class for a primitive int with some...
7
by: Christian Christmann | last post by:
Hi, in the past I always appreciated your help and hope that you also can help me this time. I've spent many many hours but still can't solve the problem by myself and you are my last hope. ...
7
by: Sammy | last post by:
Its slow but Im in the process of converting some of my admittedly ugly code into STL. At the moment Im working to change a mess that I like to call a linked list when Im in a generous mood....
35
by: Jon Slaughter | last post by:
I'm having a problem allocating some elements of a vector then deleting them. Basicaly I have something like this: class base { private: std::vector<object> V;
2
by: rockkyy | last post by:
Hi all, ok here it goes.. I am going to implement a STL MAP.. say 'mapToken'..this is a GLOBAL map. This mapToken has many nodes with its keys ranging from t1,t2,t3 ....t100 . Now in...
7
by: DJ Dharme | last post by:
Hi, I really like to use stl as much as possible in my code. But I found it really hard to understand by looking into there source code. I have no idea about what iterator traits, heaps and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.