This gives me a 'Debug Assertion Failed' _BLOCK_TYPE_IS_VALID(pHead->nBlockUse).
I don't get it what i've done wrong and what puzzles me is if I remove the function and execute what the function does in the main, it doesn't crash. Can anybody figure out what i've done wrong?
temp is an issue. When temp was declared, it was initialized by its assignment to the region which arr was pointing to. Then, when you deleted temp just before exiting the function, you deleted the region that arr was pointing to. In addition, when A1 was deleted, the memory that temp released was the region that A1 was pointing. In effect, A1 deleted memory that was no longer there.