std::map.find() is intended to return an map::iterator to an element it found if there is some or to the end() if not. I get BadPtr returned to me. The exactly same construct works fine in the other part of code. What is this?
class OntologyContainer {
map<string, OntologyClass*> data;
OntologyClass* last_added;
public:
class iterator : public std::iterator<bidirectional_iterator_tag, OntologyClass> {
map<string, OntologyClass*>::iterator itr;
public:
iterator(map<string, OntologyClass*>::iterator it) : itr(it) { }
...
}
iterator begin() {
return iterator(data.begin());
}
iterator end() {
return iterator(data.end());
}
iterator Find(const string & to_find) {
map<string, OntologyClass*>::iterator it = data.find(to_find);
// this is where it fails
return iterator(it);
}
map::iterator is wrapped for the sake of making operators * and -> returning OntologyClass objects and pointers respectively:
OntologyClass& operator* () {
return *(itr->second);
}
OntologyClass* operator->() {
return itr->second;
}