【发布时间】:2011-07-15 12:34:45
【问题描述】:
我在运行时不断收到 _BLOCK_TYPE_IS_VALID(phead->nBlockUse)。我花了 3 个小时弄乱它,发现它是由析构函数引起的?我发现当我的堆栈为空时,没有问题。但是当有什么东西时,它给了我这个错误。我在网上查了一下我的析构函数,我不知道发生了什么。这是我所有的代码。
编辑:我修复了错误,但现在出现运行时错误...?
.cpp 我试过了
stack::~stack() ////PROBLEM STILL HERE??
{
while (this)
{
top=top->next;
int x,y;
pop(x,y);
}
}
stack::~stack()
{
StackNode *nodePtr, *nextNode;
nodePtr = top;
while (nodePtr)
{
nextNode = nodePtr->next;
delete nodePtr;
nodePtr = nextNode;
}
}
stack::~stack() {
while (!isEmpty())
{ int x,y; pop(x,y); }
}
【问题讨论】:
-
你真的应该在发布之前简化它。
-
不,编辑后的代码仍然不起作用。你需要一个简单的 `while (!isEmpty()) { int x,y;流行(x,y); }` 在析构函数中。
-
@naveen 仍然错误,我需要更新头部??
标签: c++ class data-structures stack linked-list