For a class assignment I need to implement a destructor for the objects of linked-list I've created. I made a function called MakeEmpty
that I called inside the destructor. It compiled correctly the first time, but now I am getting instant crashes with an error saying:
Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
Can someone help me figure out what is wrong? I ran the debugger and pointed out where it says the error is in the code.
WORD::~WORD()
{
cout << "Destructor Called"<<endl;
(*this).MakeEmpty();
}
And this is the MakeEmpty() function
void WORD::MakeEmpty()
{
alpha_numeric *p = (*this).front;
if((*this).IsEmpty())
{
cout <<"Already empty"<< endl;
return;
}
while(front != 0)
{
front = front -> next;
delete p;//<<<<---DEBUGGER SAYS ERROR HERE
p = front;
}
return;
}