【发布时间】:2012-11-01 13:31:53
【问题描述】:
我想在双向链表中插入一个节点。我通过了位置,多项式的新系数及其幂。我没有编译错误,但是当我使用 Visual Studio 运行它时,我在 linux (g++) 中遇到了分段错误和访问冲突写入位置。
Program.exe 中 0x00bd20ba 处未处理的异常:0xC0000005:访问冲突写入位置 0xcdcdcdd9。
void Polynomial::insert( Term *pos, double newCoefficient, int power )
{
Term *newTerm = new Term; // create a new node to insert
// Link the new node to previous and next, given the position
newTerm->prev = pos->prev;
newTerm->next = pos;
newTerm->prev->next = newTerm; // Here's where I'm getting the error
newTerm->next->prev = newTerm;
// change the coefficient and power
newTerm->coefficient = newCoefficient;
newTerm->power = power;
}
我做错了什么,我该如何解决?
【问题讨论】:
-
地址
0xcdcdcdd9上面写满了调试填充器。在取消引用它们(或为此分配它们)之前验证您的输入。
标签: c++ linked-list segmentation-fault fault