471,612 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,612 software developers and data experts.

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

Jul 22 '05 #1
1 2942
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


Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Vivi Orunitia | last post: by
1 post views Thread by Dom Gilligan | last post: by
18 posts views Thread by silversurfer | last post: by
9 posts views Thread by Cyron | last post: by
14 posts views Thread by Glen Dayton | last post: by
12 posts views Thread by xgngli | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by MichaelMortimer | last post: by
1 post views Thread by ZEDKYRIE | last post: by

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.