0

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);

And my question is: what's the meaning of "*&"?Does it means that it represent the value of b itself? thx

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
kaiwii ho
  • 1,367
  • 7
  • 21
  • 40
  • See [this](http://stackoverflow.com/a/9637342/365496) to understand what the two different meanings of `&` are. Your question "Does it means that it represent the value of b itself?" makes it sound like you are confusing them and thinking that `*&b` here means "take the address of b and then dereference it." The linked answer makes it clear why it doesn't mean that in this context. – bames53 Jun 16 '12 at 01:51

2 Answers2

1

b is a reference to a pointer of A.

So if method sets b, the b in scope of the call will be changed.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
0

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.

Marlon
  • 19,924
  • 12
  • 70
  • 101
  • Well,but,if i pass the pointer into the function,like a,in my example,the function's modification of a still takes effect.Right? – kaiwii ho Jun 16 '12 at 01:53
  • It really depends on what is happening inside `method`. Anyways, this is getting beyond the scope of the question because it sounds like you do yet not have a firm grasp on how pointers and references work. The only way to truly understand them is to experiment yourself with test programs, etc. – Marlon Jun 16 '12 at 02:00