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 3 1737 Ab************* *******@yahoo.c om 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
Thanks, Victor.
That's what I needed to know.
Abraham
On Jul 9, 9:22 am, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
AbrahamLincolnI llin...@yahoo.c om 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.
: : Ab************* *******@yahoo.c om 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.c om/c++-faq-lite/how-to-post.html> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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;
|
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' Effective
STL), and reads like this:
void CGame::RemoveDeadObjects()
{
// cleanup crew!!
vector<CDrawableObject*>::iterator i;
|
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 invalidating the iterator? This
ominous statement in the STL "set" documentation makes me worried. I saw
no similar statement on the "hash_multiset" docs.
...
|
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 methods. I don't show the Integer class because it
will not add any information to my problem. Main is using some STL function.
In main you put in...
|
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.
I've a program which is using self-written double-linked lists as a data
structure. The template list consists of list elements and the list itself...
| |
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. Actually it works, but could
be much better.
When using the STL list (made up of simple pointers), I assume using the
erase function does not...
|
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;
|
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 my process many objects(of a class A) are being created( about 500).
|
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 allocators are.
So I started to write my own container class to learn templates. I
thought about a sorted vector class which have a additional two...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |