Pointer on Iterator problem...



 DEVELOP > c-Plus-Plus > Pointer on Iterator problem...

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "akush"
Date: 27 Nov 2003 04:22:52 AM
Object: Pointer on Iterator problem...
Hello!!
i try to create a pointer on an iterator for a vector list ( with more
than one values ). But if i iterate i only get the first value. if i
want to get the next the program crahes. what i have made wrong?
code example:
TestList::iterator * listIter = new TestList::iterator();
*listIter = list->begin();
Test * tt1 = **listIter;
**listIter++; // <--- works correct
Test * tt2 = **listIter;
**listIter++; // <--- crash
Thanks for help
akush
.

User: "Rolf Magnus"

Title: Re: Pointer on Iterator problem... 27 Nov 2003 06:13:26 AM
akush wrote:

Hello!!

i try to create a pointer on an iterator for a vector list ( with more
than one values ).

Why are you using pointers to iterators intead of the interators
directly?

But if i iterate i only get the first value. if i
want to get the next the program crahes. what i have made wrong?

code example:

TestList::iterator * listIter = new TestList::iterator();
*listIter = list->begin();

Test * tt1 = **listIter;
**listIter++; // <--- works correct

I don't know what you want to increment (the iterator, or the list
element?), but it increments the pointer to the iterator. So from now
on, that pointer points beyond the iterator and must not be
dereferenced anymore.

Test * tt2 = **listIter;
**listIter++; // <--- crash

.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER