Deleted and nullptr-set Pointer in a Map still shows old value in Map in Visual Studio Debugger
If I have this simple program where I add and store pointers in a Map,
struct MyStruct {
int value = 0;
std::string str;
};
int main()
{
std::map myMap;
MyStruct* obj1 = new MyStruct{ 5, "Test1" };
MyStruct* obj2 = new MyStruct{ 17, "Test2" };
myMap.insert({ "key1", obj1 });
myMap.insert({ "key2", obj2 });
// Delete obtained object
MyStruct* obtainedObj = myMap.at("key1");
delete obtainedObj;
obtainedObj = nullptr;
if (myMap.at("key1") == nullptr)
std::cout << "Confirmed\n";
else
std::cout << "Old value\n";
}
The Visual Studio Debugger shows that after I delete and set to nullptr the obtainedObj variable, even though obtainedObj becomes explicitly set to NULL, the Map's value for that key has not been changed to NULL. Also, if I check the Map's value manually, it does not satisfy the nullptr check. Am I doing something wrong?
