#include<iostream>
#include<list>
usingnamespace std;
class zahl {
public:
int wert;
};
list<zahl> L; // L ist eine Liste aus Ganzzahlen
typedef list<zahl>::iterator it;
int main(){
zahl z1;
z1.wert = 11;
L.push_back(z1);
z1.wert = 22;
L.push_front(z1);
z1.wert = 33;
L.insert(++L.begin(), z1);
for (it i=L.begin();i=L.end();i++){
cout << i->wert << "\t";
}
cout << endl;
}
/*
sgi-list.cpp: In function ‘int main()’:
sgi-list.cpp:31:31: error: could not convert ‘(i = (*(const std::_List_iterator<zahl>*)(& L.std::list<_Tp, _Alloc>::end<zahl, std::allocator<zahl> >())))’ from ‘it {aka std::_List_iterator<zahl>}’ to ‘bool’
for (it i=L.begin();i=L.end();i++){
That is the hint. (The error message mentions 31:31, which probably means "line 31, column 31". Akward.)
Lets make it a bit easier to pinpoint the error by adding some whitespace:
1 2 3 4 5 6 7 8
for (
it i=L.begin();
i=L.end();
i++ )
{
cout << i->wert << "\t";
}
cout << endl;
If you try that, I bet that the error in on the equivalent of line 3, the condition that decides whether the loop continues to iterate. Which operator do you have there?
Edit:
C++11 has a range-based for-loop syntax and a new meaning for keyword auto: