gpt4 book ai didi

c++ - 调试断言失败 : invalid iterators

转载 作者:太空宇宙 更新时间:2023-11-04 12:11:04 25 4
gpt4 key购买 nike

我目前正在模拟器上工作,在调试运行时遇到以下错误:表达式: vector 不兼容的迭代器

代码如下:

    class Network {
private:
vector<Node*> nodes;
....
void parse_config(void);
....
};

在 parse_config 方法中,我有一个生成错误的序列。就是这样:

    if(nodes.empty()) // add the first node to the network
{
Node current(regex_d[1]); // create current(first src) node
Node *acurrent = &current;

Node next_hop(regex_d[2]); // create the node we immediately send to
Node *anext_hop = &next_hop;

acurrent->add_next_hop(anext_hop);

acurrent->add_n_vchannels(regex_d[5]);

nodes.push_back(acurrent); // <== error
nodes.push_back(anext_hop); // <== here as well
}

有解决办法吗?非常感谢任何帮助/建议/引用。

塞比

最佳答案

您的指针指向堆栈对象。虽然这在您的代码中并不明显,但您的节点 vector 中很可能有一些指针已被回收。在上面:

Node *acurrent = new Node(regex_d[1]);

至少会使内存问题更准确。

至于您遇到的问题,也许内存位置被用于其他原因导致您的指针指向与节点完全不同的对象。

关于c++ - 调试断言失败 : invalid iterators,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9827374/

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