I have a map member in a class. The class is initialized well. When i try to add the first element to the map, the program crashes with Access Violation:
Exception thrown at 0x00007FFA9CCD538A (my.dll) in myprogram.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
struct S {
std::unordered_map<const A*, B*> mymap;
};
// Somewhere, S is created, accessible from somefunction.
S* s = new S();
somefunction(const A* a, B* b)
{
// s is accessible and not null.
// s->mymap is not null
// a is not null
// b is not null
//s->mymap.emplace(a, b); // fails
//s->mymap[a] = b; // also fails
auto p = std::make_pair(a, b);
s->mymap.insert(p); // also fails
}
I tried it with unordered_map as well as map. It seems some how the map is not initialized well. Why?
User contributions licensed under CC BY-SA 3.0