| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"lallous" |
| Date: |
13 Oct 2004 07:11:31 AM |
| Object: |
question about and pointer to its items |
Hello
Given this:
list<mystruct_t> lst;
lst.push_back(item1);
lst.push_back(item2);
lst.push_back(item3);
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
.
|
|
| User: "John Harrison" |
|
Title: Re: question about and pointer to its items |
13 Oct 2004 07:25:20 AM |
|
|
"lallous" <lallous@lgwm.org> wrote in message
news:2t4kfoF1qsp5tU1@uni-berlin.de...
Hello
Given this:
list<mystruct_t> lst;
lst.push_back(item1);
lst.push_back(item2);
lst.push_back(item3);
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
.
|
|
|
| User: "Sharad Kala" |
|
Title: Re: question about and pointer to its items |
13 Oct 2004 07:44:14 AM |
|
|
"John Harrison" <john_andronicus@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
.
|
|
|
|
| User: "lallous" |
|
Title: Re: question about and pointer to its items |
13 Oct 2004 07:39:06 AM |
|
|
"John Harrison" <john_andronicus@hotmail.com> wrote in message
news:2t4l39F1s60o6U1@uni-berlin.de...
"lallous" <lallous@lgwm.org> wrote in message
news:2t4kfoF1qsp5tU1@uni-berlin.de...
Hello
Given this:
list<mystruct_t> lst;
lst.push_back(item1);
lst.push_back(item2);
lst.push_back(item3);
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
.
|
|
|
| User: "John Harrison" |
|
Title: Re: question about and pointer to its items |
13 Oct 2004 07:50:46 AM |
|
|
"lallous" <lallous@lgwm.org> wrote in message
news:2t4m3eF1qr7l2U1@uni-berlin.de...
"John Harrison" <john_andronicus@hotmail.com> wrote in message
news:2t4l39F1s60o6U1@uni-berlin.de...
"lallous" <lallous@lgwm.org> wrote in message
news:2t4kfoF1qsp5tU1@uni-berlin.de...
Hello
Given this:
list<mystruct_t> lst;
lst.push_back(item1);
lst.push_back(item2);
lst.push_back(item3);
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
.
|
|
|
|
|
|

|
Related Articles |
getting items from Hashtable collections with items accessible by name? www.shopbb.com from china Wholesale Footwear, Apparel,Bag,NFLJersey,,mobile phones,shop.Best Service,Best Pruce,Best Items STL container for sorted items To Cut,Copy and Paste items to a linked list Linked list inserting items from two different funcion Order items within multiset AND Find object on multiset can I re reference items in a map
| remove items from a vector using iterator To Cut,Copy and Paste items to a linked list How to read multiple items using read ifstream in C++ Merging a list of similar items www.shopbb.com from china Wholesale Footwear, Apparel,Bag,NFLJersey,,mobile phones,shop.Best Service,Best Pruce,Best Items filtering items in a container Retrieve ListBox items
|
|
|