Compilation failure: Iterator assignment in const member function
This code fails to compile at (2) when I try to assign iterator. It
compiles if I remove 'const' qualification from the function at (1).
Is there a way I can have my 'const' and compile too?
#include <map>
using namespace std;
class Map
{
public:
void Func(int key) const // (1)
{
const map<int,void*>::iterator it = m_map.find(key); // (2):
fails to compile if 'const' is present
}
map<int,void*> m_map;
};
From Comeau online compiler:
error: no suitable user-defined conversion from
"std::_Rb_tree_iterator<
std::pair<const int, void *>,
const std::pair<const int, void *> &,
const std::pair<const int, void *>*
"
to
"const std::_Rb_tree_iterator<
std::pair<const int, void *>,
std::pair<const int, void *> &,
std::pair<const int, void *> *
"
exists
const map<int,void*>::iterator it = m_map.find(key);
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]