什么是C ++中的**? [英] What is ** in 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?
推荐答案
**不是实际上只有指向指针的指针(如在声明中),但也是dereference(在语句中)的引用。
** is not actually only pointer to pointer (as in declaration), but is also the dereference of a dereference (in a statement).
&例如参考文献。更新一个指针类型的返回值:
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 ++中的**?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!