Re: std::list::begin() returns const_iterator?
Sven wrote:
typedef helper::USmartPtr<Item> ItemPtr;
typedef std::list<ItemPtr> ItemList;
ItemList m_items; //!< list of items in this source
...
for ( ItemList::iterator it( this->m_items.begin() );
it != this->m_items.end(); ++it ) {
...
}
[...]
Using ItemList::const_iterator works here.
My guess is that you are in a const memberfunction. Inside that function,
only the const overload of list<>::begin() is available, which consequently
also returns a const_iterator.
I would interpret the error message in that way, that the begin()
methods returns something like a const_iterator which cannot be used
in the constructor for a iterator.
But if this is correct, how can I initialize the ItemList::iterator ?
A const memberfunction promises not to change the members. Since the list is
a member, it and its elements are treated as constants, too.
Uli
--
Sator Laser GmbH
Gesch?ftsf?hrer: Ronald Boers, Amtsgericht Hamburg HR B62 932
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]