Pointer to pointer or reference to pointer

A

A

The way I understand it Reference To pointer as function parameter eg.

void RP(int *&rpMem) {}

rpMem is actually an alias for the pointer outside the function right?

So I would access it exactly with the same syntax just like outside pointer
right?
 
A

A

e.g.

void RP(int &*rpMem)
{
*rpMem = 125;
rpMem++;
}

int Mem = 123;
int *pMem = &Mem; // pMem = for example 5000

*pMem = 124; // Mem = 124;

RP(pMem); // Mem = 125, pMem = 5004

Is the above correct?
 
J

Juha Nieminen

A said:
e.g.

void RP(int &*rpMem)
{
*rpMem = 125;
rpMem++;
}

int Mem = 123;
int *pMem = &Mem; // pMem = for example 5000

*pMem = 124; // Mem = 124;

RP(pMem); // Mem = 125, pMem = 5004

Is the above correct?

How about just trying it?
 
A

A

How about just trying it?

Don't you just love these kind of answers...

I did try it and now I'm just verifying and trying to make sense of all this
how to understand it the easiest way.

ref-to-ptr = alias right?
 
L

Leo Equinox Gaspard

Le 05/07/2011 18:25, A a écrit :
Don't you just love these kind of answers...

I did try it and now I'm just verifying and trying to make sense of all this
how to understand it the easiest way.

ref-to-ptr = alias right?

Yes it is.
 
A

Alain Ketterlin

A said:
ref-to-ptr = alias right?

No. ref = alias. Always. Including when referencing pointers. Your first
interpretation was correct (iirc), but you really do not need a specific
case for pointers, it works just the same as for any other kind of type.

-- Alain.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top