Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Pointer to pointer or reference to pointer

Reply
Thread Tools

Pointer to pointer or reference to pointer

 
 
A
Guest
Posts: n/a
 
      07-05-2011
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?


 
Reply With Quote
 
 
 
 
A
Guest
Posts: n/a
 
      07-05-2011
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?


 
Reply With Quote
 
 
 
 
Juha Nieminen
Guest
Posts: n/a
 
      07-05-2011
A <(E-Mail Removed)> wrote:
> 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?
 
Reply With Quote
 
A
Guest
Posts: n/a
 
      07-05-2011
> 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?


 
Reply With Quote
 
Leo Equinox Gaspard
Guest
Posts: n/a
 
      07-05-2011
Le 05/07/2011 18:25, A a écrit :
>> 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?
>
>


Yes it is.
 
Reply With Quote
 
Alain Ketterlin
Guest
Posts: n/a
 
      07-05-2011
"A" <(E-Mail Removed)> writes:

> 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.
 
Reply With Quote
 
A
Guest
Posts: n/a
 
      07-05-2011
OK, thank you. I was looking for a way how to remember that.


 
Reply With Quote
 
A
Guest
Posts: n/a
 
      07-05-2011
> ( int& *name )...

sorry, that was a typo.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reference counting and API (const reference vs pointer oriented) mathieu C++ 8 08-31-2008 09:05 AM
reference and pointer-reference kasthurirangan.balaji@gmail.com C++ 4 12-24-2007 09:05 PM
web reference interfering with reference to component Dude ASP .Net 0 11-09-2004 11:53 AM
How to tell if a reference is project or file reference from within the IDE? Darren ASP .Net 0 10-11-2004 12:51 AM
Passing the value by reference is same as pointer by reference sam pal C++ 3 07-16-2003 09:14 PM



Advertisments