F
Fab
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;
}
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? When
I do the return statement like:
return myMap.find( i )->second;
then everything works. I find the first method more elegant, but like I
said, why is this not working?
Thanks + regards
Fab
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;
}
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? When
I do the return statement like:
return myMap.find( i )->second;
then everything works. I find the first method more elegant, but like I
said, why is this not working?
Thanks + regards
Fab