Can't invoke a non-const method on objects iterated from a std::set

Jonathan Wakely cow@compsoc.man.ac.uk
Mon Nov 1 15:20:00 GMT 2004


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



More information about the Libstdc++ mailing list