G
Grey Plastic
I do not understand why this code fails to compile (under gcc):
#include <map>
using namespace std;
class Foo {
map<Foo*,int> myMap;
public:
int lookup(const Foo& f) const { myMap.find(&f); }
};
The error message states that I am discarding qualifiers by passing a
const map<...> to the map::find function. But there is a const
version of the map::find function. Why isn't the compiler using that
version?
If I replace "map<Foo*,int>" with "map<const Foo*,int>" or if I change
"lookup(const Foo& f)" with "lookup(Foo& f)" suddenly it works. Why?
I am befuddled.
How do I get this to work, without changing the signatures?
#include <map>
using namespace std;
class Foo {
map<Foo*,int> myMap;
public:
int lookup(const Foo& f) const { myMap.find(&f); }
};
The error message states that I am discarding qualifiers by passing a
const map<...> to the map::find function. But there is a const
version of the map::find function. Why isn't the compiler using that
version?
If I replace "map<Foo*,int>" with "map<const Foo*,int>" or if I change
"lookup(const Foo& f)" with "lookup(Foo& f)" suddenly it works. Why?
I am befuddled.
How do I get this to work, without changing the signatures?