Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/157.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 什么是*&;什么时候用在辩论中?_C++_Pointers_Parameters_Reference_Arguments - Fatal编程技术网

C++ 什么是*&;什么时候用在辩论中?

C++ 什么是*&;什么时候用在辩论中?,c++,pointers,parameters,reference,arguments,C++,Pointers,Parameters,Reference,Arguments,我想知道是什么意思。 背景: 功能的实现如下所示: void headInsert( Node*& head, int info ) { Node* temp = new Node(info); temp->link = head; head = temp; } 为什么不直接使用Node& 感谢节点*&表示“指向节点指针的引用”,而节点&表示“指向节点的引用” 为什么不直接使用Node& 因为headInsert函数需要更改头部指向的对象。节点*&表示“指

我想知道是什么意思。 背景:

功能的实现如下所示:

void headInsert( Node*& head, int info )
{
    Node* temp = new Node(info);
    temp->link = head;
    head = temp;
}
为什么不直接使用Node&

感谢

节点*&
表示“指向节点指针的引用”,而
节点&
表示“指向节点的引用”

为什么不直接使用Node&

因为
headInsert
函数需要更改头部指向的对象。

节点*&
表示“指向节点指针的引用”,而
节点&
表示“指向节点的引用”

为什么不直接使用Node&


因为
headInsert
函数需要更改头部指向的对象。

您可能需要查看特定调用,其中引用指针显示了它们的用途:

Node* pHead = somewhere;
headInsert(pHead, info);
// pHead does now point to the newly allocated node, generated inside headInser, 
// by new Node(info), but NOT to 'somewhere'
让我来评论一下你的例子,也许这会让它更清楚:

void headInsert( Node*& head, int info )
{
    Node* temp = new Node(info); // generate a new head, the future head
    temp->link = head; // let the former head be a member/child of the new head
    head = temp; // 'overwrite' the former head pointer outside of the call by the new head
}

您可能希望查看特定调用,其中引用指针显示了它们的用法:

Node* pHead = somewhere;
headInsert(pHead, info);
// pHead does now point to the newly allocated node, generated inside headInser, 
// by new Node(info), but NOT to 'somewhere'
让我来评论一下你的例子,也许这会让它更清楚:

void headInsert( Node*& head, int info )
{
    Node* temp = new Node(info); // generate a new head, the future head
    temp->link = head; // let the former head be a member/child of the new head
    head = temp; // 'overwrite' the former head pointer outside of the call by the new head
}

你应该用你正在使用的语言标记问题。你应该用你正在使用的语言标记问题。