This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Can't invoke a non-const method on objects iterated from a std::set
- From: Jonathan Wakely <cow at compsoc dot man dot ac dot uk>
- To: Hugues Joly <hjoly2003 at yahoo dot ca>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Mon, 1 Nov 2004 15:20:45 +0000
- Subject: Re: Can't invoke a non-const method on objects iterated from a std::set
- References: <20041030152037.93779.qmail@web41812.mail.yahoo.com>
On Sat, Oct 30, 2004 at 11:20:37AM -0400, Hugues Joly wrote:
> Hi,
> if I define a set of objects and try to invoke a
> non-const method on each of them while iterating the
> set, I get a compilation error. The gcc compiler
> complains that I try to invoke a non-constant method
> on a const object. You can see that in a sample
> program as attachment.
Set iterators are inherently const_iterators, to prevent you from
altering the object, which would invalidate the set's ordering.
i.e. set::iterator is the same type as set::const_iterator and both
point to a const object.
jon
--
"A scientific theory should be as simple as possible, but no simpler."
- Albert Einstein