Possible Duplicate:
Difference between pointer to a reference and reference to a pointer
I am newbie in C++ and I work on a pretty complicated project. When I tried to figure out something, I saw one interesting thing:
n->insertmeSort((Node *&)first);
When we deep into insertmeSort, we can see the same:
void Node::insertme(Node *&to)
{
if(!to) {
to=this;
return;
}
insertme(value>to->value ? to->right : to->left);
}
So the reason of my question is: Node *& – asterisk and ampersand, for what?
It looks pretty tricky, and interesting to me.
It a reference to a pointer. Like any regular reference, but the underlying type is a pointer.
Prior to references pointer-by-reference had to be done with double-pointers (and some C-minded folk still do, I occasionally being one of them).
Lest there be any doubt, try this to really sink it in:
Output (your values will be different , but &p == &q)
It is hopefully pretty clear that
pinfoo()is indeed a reference to pointerqinmain().