2

我在运行时遇到错误“调试断言失败”,代码如下。我用 MVC++ 2010 编译了代码,在调试模式下,当我单击错误窗口上的重试时,它会将我定向到该行的文件 dbgdel.cpp

_ASSERTE(_BLOCK_TYPE_IS_VALID(pHead->nBlockUse));

当我评论该行时

delete result;

在代码中,错误消失了......

感谢您帮助理解问题。灵魂我删除了指针结果,new 用于使用克隆方法创建它(抱歉我不能发布完整的代码,它太大了)

谢谢你的帮助

/***CODE****/



########

File: DrawShapeBase.cpp 
...
...

Base* DrawShapeBase::SetOutput(Base* data)
{
   return (data->clone());
}


....
Base* DrawShapeBase::Draw(Base* data){
    Base* result = setOutput(data); 
        ...
    ...
    return result; 

}

/*##############*/
File: Derived.cpp

...
...

Base* Derived::clone()
{
    Base* b = new Derived(*this);
    return b;
}

...
...

/*##############*/
File Base.h
public:

    Base();
    virtual ~Base();
    virtual Base* clone(void) = 0;
....


/*##############*/
main.cpp 


...
...
Base* data = new Derived();
DrawBase* dr = new DrawShapeBase();
Base* result = dr->Draw(data);

delete data;
delete result;
delete dr; 
...
4

0 回答 0