所以我有一个正确创建的链接列表,正确链接但是当我尝试取消分配内存时,我似乎无法删除任何节点,该列表仍然存在。我的列表解构器的代码:
void LL_User::free_memory() {
// TODO
LL_User_Node *currentNode;
currentNode = head;
while(currentNode) {
LL_User_Node *temp = currentNode;
currentNode = currentNode->next;
delete temp;
}
//cout << "LL_User::free_memory() is not implemented yet.\n";
}
LL_User::~LL_User() {
if(head == NULL) {
return;
}
free_memory();
}
我的用户类为 vars 和 deconstructor 提供了这个:
User::User() {
username = "";
password = "";
first_name = "";
last_name = "";
profile_pic_filename = "";
birth_year = 0;
birth_month = 0;
birth_day = 0;
}
User::~User() {
//Nothing placed in body because strings and ints are dealt with by OS?
}