【发布时间】:2020-05-12 05:11:57
【问题描述】:
我有这个功能可以删除单个链表中的第一个节点:
void removeFront(Node **tmpHead){
if ((*tmpHead)->next == NULL)
cout << "Single Node! RemoveFront() aborted!\n";'
else{
Node *oldNode = *tmpHead;
*tmpHead = oldNode->next;
delete oldNode;
}
}
为什么我需要在 if 语句中将 *tmpHead 放在括号内?如果我不这样做,则会给出编译错误。
【问题讨论】:
-
可以这样想显示错误。
-
因为它是
Node **,而不是Node *。 -
这里的
if让人分心。每当您需要查看或更改Node的内容时,都会出现同样的问题。
标签: c++ pointers dereference