[] std::map 中的运算符给了我分段错误
[] operator in std::map is giving me segmentation fault
我有一个
std::map<std::string, myClass*> myMap
然后我像下面这样插入:
if(!myKey.empty())
{
myMap[myKey] = this;
}
这有时会引发分段错误。
为什么??
也许您的 myMap 无法再访问。例如,它可能是对已删除指针的引用,或者更有可能是对已删除类的成员变量的引用:
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();
}
相关文章:
- 迭代器类的重载前缀增量运算符会引发分段错误
- 在 boost::qi 中使用过多的替代运算符会导致分段错误
- 重新定义的运算符'='导致的分段错误
- std::sort 导致运算符分段错误<
- 流输入运算符导致分段错误与 clang 但适用于 gcc
- 在重载复杂类的运算符>>时发生分段错误
- 添加两个具有运算符重载的数组对象,从而导致分段错误
- 使用重载运算符时出现分段错误
- 分段故障和过载运算符
- 一元减去运算符过载C++分段错误
- C++比较运算符重载中第一个参数为 null 时出现分段错误
- 可能的分段错误:是否正确使用了"this->"运算符?
- 运算符重载导致分段错误
- 分段错误(核心转储) 覆盖运算符时<<堆栈
- C++ 中由多个 += 运算符导致的分段错误
- 分段错误重载运算符<<
- [] std::map 中的运算符给了我分段错误
- 使用运算符 new 后出现分段故障
- 分段故障和运算符过载
- 在 std::sort() 中的自定义函数中,>(大于)运算符与 <(小于运算符)的交换会导致分段错误吗?