iterator error

Started by
3 comments, last by Joshnathan 19 years, 5 months ago
Hi all, this is my code:

for(list<int>::iterator walker = numList.begin(); walker != numList.end(); walker++)


and this is my error: 62 C:\WINDOWS\Desktop\Joshua\Tutorials\STL_Lists_Cpp\STL - Lists\main.cpp using obsolete binding at `walker' I am using dev-c++ 4.9.9.0 Nayone knows what's wrong? Joshua [Edited by - Joshnathan on November 24, 2004 10:44:21 AM]
-----------------------------Sismondi GamesStarted c++ in October 2004...
Advertisement
What headers did you include?
How is numList defined?
Have you tried ++walker rather than walker++?

By the way, it's not called a "walker", but an "iterator". [smile]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
I included
<list> and <iostream>
and numList is defined like this:
list<int> numList;
-----------------------------Sismondi GamesStarted c++ in October 2004...
IIRC, that error usually only happens when you declare a variable in a for loop (or something similar) and then reference the variable after the loop is finished. It might help if you changed your loop like:
list<int>::iterator walker;for(walker = numList.begin(); walker != numList.end(); walker++)

This will keep the variable alive past the end of the for loop.
thx a lot, it works fine now :D
-----------------------------Sismondi GamesStarted c++ in October 2004...

This topic is closed to new replies.

Advertisement