Im trying to implement a destructor for the objects of linked-list Iv created. I made a function called MakeEmpty, that I simply 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, but I cant figure out whats wrong.
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;
}
Did you obey the rule of three in your class? The error sounds like you are missing a copy constructor or a copy assignment operator.