I have a
std::map<std::string, myClass*> myMap
then I am inserting like follow:
if(!myKey.empty())
{
myMap[myKey] = this;
}
This sometime is throwing a segmentation fault.
Why??
I have a
std::map<std::string, myClass*> myMap
then I am inserting like follow:
if(!myKey.empty())
{
myMap[myKey] = this;
}
This sometime is throwing a segmentation fault.
Why??
Maybe your myMap is no longer accessible. For instance, it might be a reference to a deleted pointer, or, much more probable, a member variable of an already deleted class:
class MyClass {
public:
selfInsert(std::string myKey) {
if(!myKey.empty()) {
myMap[myKey] = this;
}
}
private:
std::map<std::string, myClass*> myMap;
}
int main()
{
MyClass *a = new MyClass();
delete a;
a->selfInsert();
}