what's the meaning of *&

后端 未结 2 1614
鱼传尺愫
鱼传尺愫 2021-01-27 11:39

I am a java coder and not familar with the c++ language. But right now,i read the following code:

void method(A* a,A*& b);

A *a;
A *b;
method(a,b);
<         


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-01-27 11:50

    Read it from right to left. A*& b says that b is a reference to an object that points to an A. Why is this useful? It allows you to directly modify the pointer that is being passed into the function. Whatever happens to b inside that function will be visible when the function returns.

提交回复
热议问题