EXC_BAD_ACCESS (code=1, address=0x10))??在这种情况下这意味着什么

EXC_BAD_ACCESS (code=1, address=0x10))??? What does this mean in this context?

本文关键字:什么 意味着 0x10 这种情况下 ACCESS BAD code EXC address      更新时间:2023-10-16

我正在构建一个遗传算法,我有一个问题。这是一个记忆的问题,我仍然是新的和malloc的东西,我需要使用它吗?如果有人能解释一下这个错误,我将不胜感激。在K的第4个增量之后,我得到EXC_BAD_ACCESS (code=1, address=0x10)的错误。它会卡在

tmp.at(0) = it_1->first;

void Population::Poppairing(int j)
{
int rand_num = 0;
int rand_per = 0;
for (unsigned long i = select.size(); i-=2;)
{
    rand_per = rand()%100;
    if(j < rand_per)
    {
        auto temp_1 = parents.at(select.at(i)).get_genome();//auto here is unordered map
        auto temp_2 = parents.at(select.at(i-1)).get_genome();
        auto it_1 = temp_1.begin();//here it is and iterator
        auto it_2 = temp_2.begin();
        for(int k = 0;k < no_rule; k++)
        {
            rand_num = rand() % no_in;
            advance(it_1,k);
            advance(it_2,k);
            vector<string > tmp(2);
            for(int l = 2; l--;)
            {
                tmp.at(0) = it_1->first;//father 
                tmp.at(1) = it_2->first;//mother
                tmp.at(l).erase((tmp.at(l).begin()+rand_num),tmp.at(l).end());
                tmp.at((!l)).erase(tmp.at((!l)).begin(),(tmp.at((!l)).end()-((tmp.at(!l)).size()-rand_num)));
                children.at(i-l).set_input_pos((tmp.at(l)+tmp.at(!l)),k);
                children.at(i-l).set_output_pos((unsigned char)(parents.at(i-l).get_genome().begin()->second),k);
            }
            tmp.clear();
        }
        children.at(i).re_initialising_map();
        children.at(i-1).re_initialising_map();
    }
    else
    {
        children.at(i) = parents.at(select.at(i));
        children.at(i-1) = parents.at(select.at(i-1));
    }
}
}

我修复了它,似乎从iterator stl使用advance有问题。只是增加了k for循环末尾的it_1和2。