What is ** in C++?(C++中的**是什么?)
问题描述
我已经看到一些代码,以及我的编译器生成的一些错误,这些错误在变量之前有一个 '**
' 标记(例如 **variablename unreferenced-- 或其他东西,我可以不记得完全是偶然的).我相当肯定这与指针有关,如果我不得不猜测它看起来像是试图取消引用两次.'**
' 是相当无法谷歌的.有人可以给我指出一个好的网站/文档,还是有人愿意在这里解释一下?
I've seen some code, as well as some errors generated from my compiler that have a '**
' token before the variable (eg **variablename unreferenced-- or something, I can't recall exactly offhand). I'm fairly certain this is related to pointers, if I had to guess it looks like it's trying to dereference twice. '**
' is fairly ungoogleable. Can someone point me to a good website/documentation or would someone care to explain it here?
谢谢.
很好的回应.如果我可以添加,在哪些情况下使用指向指针的指针是有用的?难道您不应该只使用原始指针而不是创建另一个指向原始指针的指针吗?
Great responses. If I can add, what would be some situations where it is useful to have a pointer to a pointer? Shouldn't you just be using the original pointer instead of creating yet another pointer to the original pointer?
推荐答案
**
实际上不仅是指向指针的指针(如在声明中),而且还是一个解引用的解引用(在一个声明).
**
is not actually only pointer to pointer (as in declaration), but is also the dereference of a dereference (in a statement).
它经常在没有 & 的 C 中使用.参考符号,例如更新一个指针类型的返回值:
It is used often in C which does not have the & notation for references, e.g. to update a return value which is a pointer type:
int alloc_foo(struct foo **foo_ret)
{
*foo_ret = malloc(sizeof(struct foo));
return 1; /* to indicate success; return value in foo_ret */
}
这篇关于C++中的**是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++中的**是什么?


基础教程推荐
- 初始化列表*参数*评估顺序 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- CString 到 char* 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16