Const-Iterator?
-
Hallo,
ich hab mal wider ein Problem. Ich krieg die Meldung:
In function `std::ostream& operator<<(std::ostream&, const
Aktiengruppe&)':
aktiengruppe.cpp:30: error: no match for 'operator=' in 'it = std::list<_Tp,_Alloc>::begin() const [with _Tp = Aktie, _Alloc = std::allocator<Aktie>]()'
/usr/include/g++/bits/stl_list.h:144: error: candidates are:
std::_List_iterator<Aktie, Aktie&, Aktie*>& std::_List_iterator<Aktie, Aktie&, Aktie*>::operator=(const std::_List_iterator<Aktie, Aktie&, Aktie*>&)Hier meine Code:
class Aktiengruppe { public: Aktiengruppe(); ~Aktiengruppe(); std::list<Aktie> aktien; }; std::ostream& operator << (std::ostream& os, const Aktiengruppe& gruppe) { std::list<Aktie>::iterator it; for(it = (gruppe.aktien).begin(); it != (gruppe.aktien).end(); it++ ) { os << it->bezeichnung << std::endl; } return os; }Meine Interpretation:
Da die Aktiengruppe als const-Referenz übergeben wird, muss der Iterator it das berücksichtigen und auch irgendwie const sein. Aber wie? Oder ist das völlig falsch?Gruss, Karl
-
std::list<Aktie>::const_iterator it;
-
wow - das ging ja schnell
Vielen Dank,Karl