当调用析构函数时,我正在处理一个大代码并且程序崩溃。我正在指定失败的地方:
Application::~Application()
{
for ( int blockId=0; blockId< m_noBlocks; blockId++ ) {
if ( m_blocks[ blockId ] ) {
delete m_blocks[ blockId ]; //error here
m_blocks[ blockId ] = NULL;
}
if ( m_methods[ blockId ] ) {
delete m_methods[ blockId ];
m_methods[ blockId ] = NULL;
}
}
}
该程序完全在“错误此处”中提到的删除操作处崩溃。但是,如果我评论该行,该程序似乎工作正常。有人可以扔灯吗,可能是什么问题?
编辑:它们在构造函数中使用new
. m_noBlocks
用一个值定义,此处未指定:
Application::Application(){
m_blocks = new ZFSBlock*[m_noBlocks];
m_methods = new ZFSMethods*[m_noBlocks];
for ( int blockId=0; blockId< m_noBlocks; blockId++ ) {
m_methods[ blockId ] = NULL;
m_blocks[ blockId ] = NULL;
}
}
但是,稍后在代码的主要部分内部进行了m_methods
实际分配。m_blocks