This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: hash_map error: passing `const lambda_calculus::int_adr' as `this' argument of `const size_t lambda_calculus::int_adr::operator ()(const lambda_calculus::Port *)' discards qualifiers passing `const lambda_calculus::int_adr' as `this' argument of `const size_t lambda_calculus::int_adr::operator ()(const lambda_calculus::Port *)' discards qualifiers
- From: "Alex J. Dam" <alexjdam at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 4 Nov 2005 23:53:04 -0200
- Subject: Re: hash_map error: passing `const lambda_calculus::int_adr' as `this' argument of `const size_t lambda_calculus::int_adr::operator ()(const lambda_calculus::Port *)' discards qualifiers passing `const lambda_calculus::int_adr' as `this' argument of `const size_t lambda_calculus::int_adr::operator ()(const lambda_calculus::Port *)' discards qualifiers
- References: <20051105012503.96334.qmail@web50408.mail.yahoo.com>
On Fri, Nov 04, 2005 at 10:25:03PM -0300, Ricardo Fodra wrote:
> Having a similar problem here:
>
> std::set<Person>* _family
> ...
> set<Person>::reverse_iterator iter =
> _family->rbegin();
> ++iter;
> > iter->setName(NULL);
>
> error: passing `const Person' as `this' argument of
> `void Person::setName(char*)' discards qualifiers
>
> Why is the compiler thinking *iter is a "const
> Person"? _family is not const and I'm not using a
> const_reverse_iterator, although there are some
> const_iterator in other parts of the code.
>
I think it's because you're not supposed to change the values stored
in a set.
Values are stored in a set using the operator<, so if you insert these
names in a set, in this order:
julia
amanda
gloria
The set will store them internally like this, for fast retrieval:
amanda
gloria
julia
What if you change the first entry (amanda) to something else? The
set will get lost: it will not be able to access its elements
properly. The same happens to std::map.