By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,370 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

Pointer on Iterator problem...

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.