aguess

hi
i am converting some codes from vc++ express to vc++ 2005 (mfc),and i was working with
LinkedListNode who has the Properties "NEXT" and "PREVIOUS" ,but now i am working with
the class "list" and i use typedef iterator to browse the list,but i coundn't find the
replacement of the Properties "NEXT" and "PREVIOUS" .



Re: Visual C++ General problem with list properties

Jonathan Caves - MSFT

If you are using std::list and std::list::iterator then you use the ++ and -- operators to move the iterator forward and backwards.

Something like:

Code Snippet

std::list<int> myList;

std::list<int>::iterator iter = myList.begin();

++iter; // Advance one

--iter; // Backup one






Re: Visual C++ General problem with list properties

aguess

is there a difference between ++iter and iter++




Re: Visual C++ General problem with list properties

Jonathan Caves - MSFT

In the case of simple statements like:

Code Snippet

++iter;

iter++;

there is no real difference (a different function may be called but in a well-formed system the overall result should be the same). But watch out for statements like:

Code Snippet

iter2 = ++iter1;

iter2 = iter1++;

In this case there is a difference






Re: Visual C++ General problem with list properties

aguess

using the operators (++) and (--) don't resolve my problem ,because if i use the my pointer will increase or decrease to next or previouse record of the list. in my case i want just to test the value of the next or the previouse record without moving the pointer of the list.

in the LinkedListNode ,the propreties Previous and Next give you the value without moving the pointer.

thank you,and hope that i was clear .





Re: Visual C++ General problem with list properties

Holger Grund

You can still keep a copy of the previous iterator. E.g.:

Code Snippet

iterator next = current_iterator;

++next;

if (*next == 4711) { ... }

*current_itererator = 0x815;

In fact, this little utility is quite useful and consequently wrapped in a function in some support libraries, e.g. in Boost (http://www.boost.org/libs/utility/utility.htm#functions_next_prior)

For random access iterators you could also use *(iter+1), but lists don't support fast random access and therefore no operator+ on its iterators.

All that being said, you may want to read up on STL containers, iterators and algorithms.

-hg





Re: Visual C++ General problem with list properties

aguess

i think that could work better iter_Ptr->_Prev