What does *& mean in a function parameter

前端 未结 5 1098
春和景丽
春和景丽 2020-12-03 14:43

If I have a function that takes int *&, what does it means? How can I pass just an int or a pointer int to that function?

function(int *&am         


        
5条回答
  •  猫巷女王i
    2020-12-03 15:39

    Simply: a reference to a pointer.

    In C, without references, the traditional way to "relocate" a pointer, is to pass a pointer to a pointer:

    void c_find(int** p, int val); /* *p will point to the node with value 'val' */
    

    In C++, this can be expressed by the reference syntax, to avoid the awkward double dereference.

    void cpp_find(int*& p, int val); // p will point to the node with value 'val'
    

提交回复
热议问题