This question already has an answer here:
I have created a hash map and an iterator using the below lines:
std::map<const char*,vaLueClass *> myCache;
std::map<const char*,vaLueClass *>::iterator myCacheIterator;
Then I insert into this map using the below line:
myCache[anotherObject->getStringKey()] = new vaLueClass(anotherObj1->getIntAttr(), anotherObj1-->getIntAttr());
Then whenever I tried to search if an ENTRY for a particular string exist in this map or nut using below lines, it always enters the IF block which in other words it does not find any entries inside this map.
myCacheIterator= myCache.find(sampleObject->getstringKey());
NOTE: here sampleObject->getstringKey() returns the same key which has been inserted earlier.
if (myCacheIterator.operator ==(myCache.end())){
// this block means that no matched entry is found inside the map myCache
}
Please help. Also, is this the proper way to create and use std::map in c++ ? If not then please suggest one.
Also, I have not used the keyword new
to create the std::map object.
Aucun commentaire:
Enregistrer un commentaire