I have a hash table of nodes. In my constructor, I initialize every element of the hash table to NULL. My code compiles, but after the executable ends, it has the following error: "Debug Assertion Failed!" Program: /pathname/ File:f:\dd\vctools\crt_bld\self_x86\crt\src\dbgdel.cpp line: 52
Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
My Implementation for constructor and destructor:
// Constructor
Hash::Hash() {
for(int i = 0; i < tableSize; i++) {
Hash_Table[i] = NULL; // Will be used to indicate an empty bucket
}
}
//
//
// Destructor
Hash::~Hash() {
song* temp;
song* temp_next;
for(int i = 0; i < tableSize; i++) { // For every bucket
if(NULL != Hash_Table[i]) { // If the bucket is not already empty
temp = Hash_Table[i];
while(NULL != temp) {
delete[] temp->artist;
delete[] temp->title;
delete[] temp->playlists;
delete[] temp->album;
temp_next = temp->next;
delete temp;
temp = temp_next;
} // end while loop
Hash_Table[i] = NULL;
} // end if
} // end for loop
delete[] Hash_Table;
} // end destructor
cerrtrace to document the pointers and operations on them, see what's mismatched, but I suggest you usestd::unordered_map<>orstd::map<>andstd::string- you'll find life much easier. - Tony DelroyHash_Table? In the code there is nonewfor it.delete[]here also seems unreasonable. - Xiangyan Sun