*&在论证中使用时是什么意思?
What does *& mean when used in argument?
我想知道是*&means。上下文:
函数的实现方式如下:
void headInsert( Node*& head, int info )
{
Node* temp = new Node(info);
temp->link = head;
head = temp;
}
谁不只是使用Node&?
谢谢
Node*&
表示"对指向节点的指针的引用",而Node&
表示"对节点的引用"。
为什么不直接使用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
}
相关文章:
- 这个语法std::class<>{}(arg1, arg2) 在C++中是什么意思?
- 标准 N3337 5.2.10 第 7 条中的C++"类型"是什么意思?
- "类模板示例<int>;"语句对 C++11 是什么意思?
- 线应该是什么意思
- "CID"在AT+HTTPPARA= "CID" ,1中是什么意思
- 表达式"b=(b-x)&x"是什么意思?
- 这个表达是什么意思?
- 此代码验证公式是什么意思?
- 跟踪日志中的T.11803()是什么意思?
- 这个额外的关键字在这个 c++ 类声明中是什么意思?
- * 和 ** 在 C++ 函数声明中是什么意思?
- _T("xyz")是什么意思?
- #define Dbg(fmt,..) (0) 是什么意思? 警告:表达式无效
- 这行代码到底是什么意思?
- 在命名空间名称之前加上 :: 是什么意思?
- 从字符数组的元素中减去'a'是什么意思
- "friend"关键字在C++中是什么意思?
- 减法中的"0"是什么意思?
- 字符数组前面的加号是什么意思?
- 这里的字符串函数是什么意思