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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux