|
From: <h.r...@gm...> - 2002-10-21 21:26:25
|
> Hello all,
>
> I get an errormessage when I compile and I can't figure out what the
> problem is.
> Here's the code
>
> #include <iostream>
> #include <list>
>
> int main(int argc, char *argv[]){
> list<int> initialWeightList;
> for(int i=0; i<10; i++)
> initialWeightList.push_back(i);
>
> list<int>::iterator iter;
> for(
> iter = initialWeightList.begin();
> iter < initialWeightList.end(); // <--- error ?!?!?!
> iter++
> ){
> cout << "Here i do something" << endl;
> }
> }
>
> and here's the errormessage
>
> 12 D:\Programmering\IDE\Dev-Cpp\__Projects\Test\main.cpp
> no match for `_List_iterator<int,int &,int *> & < _List_iterator<int,int
> &,int *>'
>
> The for-statement is split up so I can locate the error
>
> Any ideas?
> If I replace all list<int> by vector<int>, and include <vector> ofcourse,
> it works just fine.
>
> Regards
> /Jörgen
>
>
Hi,
This works (with mingw2.0.0-3):
#include <iostream>
#include <list>
using namespace std;
int main(int argc, char *argv[]){
list<int> initialWeightList;
for(int i=0; i<10; i++)
initialWeightList.push_back(i);
list<int>::iterator iter;
for(
iter = initialWeightList.begin();
iter != initialWeightList.end(); // <--- error ?!?!?!
iter++
){
cout << "Here i do something" << endl;
}
system("PAUSE");
}
I think it is wrong to compare two iterators with < because in a list the
items are anywhere in the memory and not in order (as in vector). Iterators are
like pointers. You can compare it with == or !=.
regards
Horst
--
+++ GMX - Mail, Messaging & more http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!
|