这不是技巧,它只是类型——“对指针的引用Node
”。
n->insertmeSort((Node *&)first);
调用insertmeSort
结果first
为 a Node*&
。
void Node::insertme(Node *&to)
声明insertme
将指向 a 的指针的引用Node
作为参数。
引用和指针如何工作的示例:
int main() {
//Initialise `a` and `b` to 0
int a{};
int b{};
int* pointer{&a}; //Initialise `pointer` with the address of (&) `a`
int& reference{a};//Make `reference` be a reference to `a`
int*& reference_to_pointer{pointer_x};
//Now `a`, `*pointer`, `reference` and `*reference_to_pointer`
//can all be used to manipulate `a`.
//All these do the same thing (assign 10 to `a`):
a = 10;
*pointer = 10;
reference = 10;
*reference_to_pointer = 10;
//`pointer` can be rebound to point to a different thing. This can
//be done directly, or through `reference_to_pointer`.
//These lines both do the same thing (make `pointer` point to `b`):
pointer = &b;
reference_to_pointer = &b;
//Now `b`, `*pointer` and `*reference_to_pointer` can
//all be used to manipulate `b`.
//All these do the same thing (assign 20 to `b`):
b = 20;
*pointer = 20;
*reference_to_pointer = 20;
}