473,587 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question about <list> and pointer to its items

Hello

Given this:

list<mystruct_t > lst;

lst.push_back(i tem1);
lst.push_back(i tem2);
lst.push_back(i tem3);

Now say I have this:

mystruct_t *p1, *p2, *p3 pointing to item1->item3 memory in side the list.

If I delete "item2" (or second item) will the other pointers still be valid?

--
Elias
Jul 22 '05 #1
4 1288

"lallous" <la*****@lgwm.o rg> wrote in message
news:2t******** *****@uni-berlin.de...
Hello

Given this:

list<mystruct_t > lst;

lst.push_back(i tem1);
lst.push_back(i tem2);
lst.push_back(i tem3);

Now say I have this:

mystruct_t *p1, *p2, *p3 pointing to item1->item3 memory in side the list.

If I delete "item2" (or second item) will the other pointers still be valid?


If you use iterators instead of pointers (like you should) then the C++
standard guarantees that the iterators will remain valid. I don't know that
the standard guarantees that pointers will be OK, but its very likely to
work.

John
Jul 22 '05 #2
"John Harrison" <jo************ *@hotmail.com> wrote in message
news:2t******** *****@uni-berlin.de...

"lallous" <la*****@lgwm.o rg> wrote in message
news:2t******** *****@uni-berlin.de...
Hello

Given this:

list<mystruct_t > lst;

lst.push_back(i tem1);
lst.push_back(i tem2);
lst.push_back(i tem3);

Now say I have this:

mystruct_t *p1, *p2, *p3 pointing to item1->item3 memory in side the
list.

If I delete "item2" (or second item) will the other pointers still be

valid?


If you use iterators instead of pointers (like you should) then the C++
standard guarantees that the iterators will remain valid. I don't know
that
the standard guarantees that pointers will be OK, but its very likely to
work.


You mean I change p1, p2, p3 to:
list<mystruct_t >::iterator p1, p2, p3;

then have p1, p2, p3 point to each element, then when any element is deleted
the other iterators are still valid?

--
Elias
Jul 22 '05 #3

"John Harrison" <jo************ *@hotmail.com> wrote in message
If you use iterators instead of pointers (like you should) then the C++
standard guarantees that the iterators will remain valid.


I think Standard only talks of iterators and references remaining valid, and
am too lazy to check the Standard :-)

Sharad
Jul 22 '05 #4

"lallous" <la*****@lgwm.o rg> wrote in message
news:2t******** *****@uni-berlin.de...
"John Harrison" <jo************ *@hotmail.com> wrote in message
news:2t******** *****@uni-berlin.de...

"lallous" <la*****@lgwm.o rg> wrote in message
news:2t******** *****@uni-berlin.de...
Hello

Given this:

list<mystruct_t > lst;

lst.push_back(i tem1);
lst.push_back(i tem2);
lst.push_back(i tem3);

Now say I have this:

mystruct_t *p1, *p2, *p3 pointing to item1->item3 memory in side the
list.

If I delete "item2" (or second item) will the other pointers still be valid?


If you use iterators instead of pointers (like you should) then the C++
standard guarantees that the iterators will remain valid. I don't know
that
the standard guarantees that pointers will be OK, but its very likely to
work.


You mean I change p1, p2, p3 to:
list<mystruct_t >::iterator p1, p2, p3;

then have p1, p2, p3 point to each element, then when any element is

deleted the other iterators are still valid?


Yes.

john
Jul 22 '05 #5

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

Similar topics

5
8700
by: G?nter Omer | last post by:
Hi there! I'm just trying to compile a header file (unsing Borland C++ Builder 10)implementing a class, containing the declaration of the STL <list> but it refuses to work. The following errors occure: "test.h" line 29 type name expected "test.h" line 29 declaration missing
5
6226
by: Kenneth | last post by:
<list> seems to be a powerful structure to store the related nodes in memory for fast operations, but the examples I found are all related to primitive type storage. I'm doing a project on C++ with my defined classes to be added to linked list structure so as to facilitate the operation of all instances of defined classes. Is that possible to...
2
2064
by: Tom Vogel | last post by:
I'd like to use the XML Documentation Tags to comment my C# code. But many of the tags do not have any effect when I execute the "Build Comment Web Pages" menu. For example, the <list> tag gets reendered as is. The resulting HTML page contains the exact same tags, which are not valid HTML. The same with <see> or <see also>. Isn't this...
1
1428
by: Steffo | last post by:
Why can't I use stl list in my dll. I'ts no problem with vector, but when trying list I get the followning error msg: error C2061: syntax error : identifier 'list' Hu!! S.
3
2228
by: kuiyuli | last post by:
I'm using VC++ .Net to do a simlple program. I tried to use <vector> <list> in the program, and I simply put the folowing lines " #include <list> #include <vector> #include <string> using namespace std; ...... vector <Vector> vectorlist;
4
2515
by: glumaka | last post by:
Hi there 1 This part has no problem with compilation, but further I don't know how to access "item". Pls help ! Thx ! { typedef double tab; std::list<tab> tbBigList; tab tb; tb=0.1; tb=0.2;
17
2089
by: Cralis | last post by:
I am trying to populate a ListView with a list of 'Models' of cars. I have a data object class for my models, which has a function, 'getListOfModels', which I want to retuyrn a <Listof models. In my data object, I have also created a class to hold each model, as shown below. No database work has been done. Just adding a model, and trying...
5
2528
by: Deadlocker | last post by:
Hallo, Ive already found an answer : http://www.thescripts.com/forum/thread59807.html But it doesn't work.. here is the error message I get : C:\Dokumente und Einstellungen\piouf.cpp(121) : error C2664: 'void __thiscall std::list<class AElement *,class std::allocator<class AElement *> >::sort(struct std::greater<class AElement *>)' :...
12
2635
by: arnuld | last post by:
It works fine. any advice on making it better or if I can improve my C++ coding skills: /* C++ Primer - 4/e * * Chapter 9 - Sequential Containers * exercise 9.18 - STATEMENT * Write a program to copy elements from a list of "ints" * to 2 "deques". The list elements that are even should go into one deque * and even...
0
7920
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8215
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, 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. ...
0
8347
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8220
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 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...
1
5718
isladogs
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...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2358
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
0
1189
bsmnconsultancy
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...

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.