I am trying to write a copy constructor for an object managing an STL map containing pointers, where the key is a string. However, when I try to insert new values ββinto the map, the pointers are NULL:
for(std::map<std::string, data_base*, order>::const_iterator it = other.elements.begin();
it != other.elements.end(); ++it){
data_base *t = it->second->clone();
std::cout << "CLONE: " << std::hex << t << std::endl;
elements[it->first] = t;
std::cout << "INSERTED: " << std::hex << elements[it->first] << std::endl;
}
other- copied object and elementsmap. The method clone()returns a pointer to a new object (via new).
By executing the code above, I get something like:
CLONE: 0xcfbbc0
INSERTED: 0
I am not a very experienced programmer, and this problem is probably easy to fix, but I did not find any solution to find it.
Thanks so much for your time.
source
share