Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #7476 > unrolled thread
| Started by | "A" <a@a.a> |
|---|---|
| First post | 2011-07-05 17:50 +0200 |
| Last post | 2011-07-05 21:49 +0200 |
| Articles | 9 — 5 participants |
Back to article view | Back to comp.lang.c++
Pointer to pointer or reference to pointer "A" <a@a.a> - 2011-07-05 17:50 +0200
Re: Pointer to pointer or reference to pointer "A" <a@a.a> - 2011-07-05 17:53 +0200
Re: Pointer to pointer or reference to pointer Juha Nieminen <nospam@thanks.invalid> - 2011-07-05 16:04 +0000
Re: Pointer to pointer or reference to pointer "A" <a@a.a> - 2011-07-05 18:25 +0200
Re: Pointer to pointer or reference to pointer Leo Equinox Gaspard <ekinox1995@gmail.com> - 2011-07-05 19:57 +0200
Re: Pointer to pointer or reference to pointer Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2011-07-05 21:26 +0200
Re: Pointer to pointer or reference to pointer "A" <a@a.a> - 2011-07-05 21:47 +0200
Re: Pointer to pointer or reference to pointer Werner Erasmus <werasm@gmail.com> - 2011-07-05 21:47 +0200
Re: Pointer to pointer or reference to pointer "A" <a@a.a> - 2011-07-05 21:49 +0200
| From | "A" <a@a.a> |
|---|---|
| Date | 2011-07-05 17:50 +0200 |
| Subject | Pointer to pointer or reference to pointer |
| Message-ID | <iuvbtf$vo7$1@gregory.bnet.hr> |
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?
[toc] | [next] | [standalone]
| From | "A" <a@a.a> |
|---|---|
| Date | 2011-07-05 17:53 +0200 |
| Message-ID | <iuvc30$vr8$1@gregory.bnet.hr> |
| In reply to | #7476 |
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?
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2011-07-05 16:04 +0000 |
| Message-ID | <4e13361a$0$2844$7b1e8fa0@news.nbl.fi> |
| In reply to | #7477 |
A <a@a.a> 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?
[toc] | [prev] | [next] | [standalone]
| From | "A" <a@a.a> |
|---|---|
| Date | 2011-07-05 18:25 +0200 |
| Message-ID | <iuvdvf$3dq$1@gregory.bnet.hr> |
| In reply to | #7479 |
> 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?
[toc] | [prev] | [next] | [standalone]
| From | Leo Equinox Gaspard <ekinox1995@gmail.com> |
|---|---|
| Date | 2011-07-05 19:57 +0200 |
| Message-ID | <iuvja1$s8m$2@dont-email.me> |
| In reply to | #7480 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Alain Ketterlin <alain@dpt-info.u-strasbg.fr> |
|---|---|
| Date | 2011-07-05 21:26 +0200 |
| Message-ID | <87iprg1qbu.fsf@dpt-info.u-strasbg.fr> |
| In reply to | #7480 |
"A" <a@a.a> 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.
[toc] | [prev] | [next] | [standalone]
| From | "A" <a@a.a> |
|---|---|
| Date | 2011-07-05 21:47 +0200 |
| Message-ID | <iuvpp0$ni5$1@gregory.bnet.hr> |
| In reply to | #7490 |
OK, thank you. I was looking for a way how to remember that.
[toc] | [prev] | [next] | [standalone]
| From | Werner Erasmus <werasm@gmail.com> |
|---|---|
| Date | 2011-07-05 21:47 +0200 |
| Message-ID | <eMGdnb-pH9Pd947TnZ2dnUVZ8jKdnZ2d@saix.net> |
| In reply to | #7480 |
A wrote: >> How about just trying it? I think he assumes you never tried it because it doesn't compile. "Trying" it in codepad (http://codepa.org) I get the following error: Line 1: error: cannot declare pointer to 'int&' compilation terminated due to -Wfatal-errors. This OTOH would work: void RP(int*& rpMem); ( int& *name )... name is a pointer to a reference, and there is no such thing in c++. > Don't you just love these kind of answers... [snip] > ref-to-ptr = alias right? Yes, you can see it as an alias to T that at least has to be initialized with a valid T (where T is a pointer in your case). See: http://www.parashift.com/c++-faq-lite/references.html and also: http://en.wikipedia.org/wiki/C%2B%2B_reference Regards, Werner
[toc] | [prev] | [next] | [standalone]
| From | "A" <a@a.a> |
|---|---|
| Date | 2011-07-05 21:49 +0200 |
| Message-ID | <iuvprp$nkj$1@gregory.bnet.hr> |
| In reply to | #7492 |
> ( int& *name )... sorry, that was a typo.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web