I am having the error "Debug Assertion Failed" at the run time with the code below. I compiled the code with MVC++ 2010, in debug mode when I click on retry on the error window it directs me to the file dbgdel.cpp at the line
_ASSERTE(_BLOCK_TYPE_IS_VALID(pHead->nBlockUse));
When I comment the line
delete result;
in the code, the error disappears...
I would appreciate your help to understand the problem. Sould I delete the pointer result, new is used to create it with clone method (Sorry I can't post the full code and it is too big)
Thanks for your help
/***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;
...