Hello!
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 direct me to the file dbgdel.cpp at the line
_ASSERTE(_BLOCK_TYPE_IS_VALID(pHead->nBlockUse));
When I comment in the code the line
delete result;
/* code */
The error disappears... I would appreciate your help to understand the problem. Sould I delete the pointer result, new is used to created with clone method
(Sorry I can't post the full code and it is too big)
Yes, this is the problem. When you delete an object by pointer to a base class, in order for correct destructor to be called, the base-class destructor should be declared as virtual: virtual ~Base();
Most likely this causes your debug assertion. In Release production code this might lead to either memory leak or a crash.
Use smart pointers, as suggested above.
This will solve most of the problems, if not all, and also helps you building better programs in an easier way.
> I use delete for dr, data, (both are 'new' pointers) and result,
¿is there something that you don't new/delete?
You do know that you can declare objects, ¿right?
Again, try to create a minimal example that does reproduce your issue.