Pointer on Iterator problem...

A

akush

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
 
R

Rolf Magnus

akush said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top