Edit where a pointer points within a function

后端 未结 3 1208
温柔的废话
温柔的废话 2021-01-01 01:42

I have a pointer to a struct object in C++.

 node *d=head;

I want to pass that pointer into a function by reference and edit where it point

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-01 02:42

    Pass a node ** as an argument to your function:

    // f1 :
    node *d = head;
    
    f2(&d);
    
    // f2:
    void f2(node **victim) {
        //assign to "*victim"
    }
    

提交回复
热议问题