gpt4 book ai didi

c++ - unordered_map 如何导致 sigsegv

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:38:51 24 4
gpt4 key购买 nike

<分区>

编辑:已解决,我知道怎么做,但我不明白为什么。

我改变了variables来自

的声明
tr1::unordered_map<int,T> variables;

unordered_map<int,T> variables;

它工作正常。

如果您知道原因,请将其写在答案中。

我有一个非常大的程序,所以我不知道应该把哪个代码放在这里。

有抽象类,继承派生类。摘要有unordered_map<int,int> (模板)作为私有(private)成员和公共(public)方法 insert(int,int) .

派生类使用基类insert将元素插入到 unordered_map<int,int> 的方法容器,

第一个int像计数器一样使用,从 0 开始。前 11 个插入元素正常。但在第 12 个元素中,我得到了 sigsegv,并在 struct equal_to 中出错在 STL_function.h(209)。

在调试器中,我看到 unordered_map 的 bucket_count 等于 11,这可能是某种线索。

我的编译器是 gcc 4.6.1。

也许您可以在 unordered_map.insert 中概括地写下什么可以 导致 sigsegv ?

谢谢,抱歉我的英语不好。

如果我知道的话,我会带来具体的代码。

编辑:这是 insert方法:

virtual void Insert(int arrayPlace, T value)
{
if (!isReadOnly)
{
if (IsValueDataValid(value))
{
variables[arrayPlace] = value;
}
else
{
throw 2;
}
}
else
{
throw 4;
}
};

声明是:

tr1::unordered_map<int,T> variables;

sigsegv 发生在 arrayPlace 时==11,什么都没有关系value相等。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com