On 11/12/12 10:20, Fab wrote:
> Dear all
>
> I use std::map for some application. I would like to return a const
> reference to some value with the operator[] function. I have a public
> method of the following form:
>
> const value& getValue( const int i ) const
> {
> return myMap[i];
> }
>
> where myMap is of type std::map. When I compile this with gcc, I get an
> error due to the const method qualifier. I can't figure out why?
Map's operator[] isn't const. It will modify the map (by inserting a
default value) if the element does not exist.
--
Ian Collins