Re: better understanding references
From: Greg Comeau (comeau_at_panix.com)
Date: 03/04/04
- Next message: Greg Comeau: "Re: better understanding references"
- Previous message: Thomas Matthews: "Re: Optimizing a switch statement"
- In reply to: David White: "Re: better understanding references"
- Next in thread: David White: "Re: better understanding references"
- Reply: David White: "Re: better understanding references"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 4 Mar 2004 08:34:19 -0500
In article <IBy1c.2736$KS1.102886@nasal.pacific.net.au>,
David White <no@email.provided> wrote:
>"thides" <swatts@globalserve.net> wrote in message
>news:67y1c.68104$9j1.25598@nntp-post.primus.ca...
>> I guess if a changes then so will b. And if b changes so will a.
>>
>> Like this:
>>
>> int a;
>> int &b=a;
>>
>> b=4; // therefore a=4
>
>Correct.
>
>> But that wont work because b is a reference to a value not a value
>itself...
>
>What do you mean "that won't work"?
I suspect that thides is thinking that:
int a = 99;
int &b = a;
since often a use of a means 99, that the reference is referring
to that and not a, after all, we don't use &a. However, b is
indeed referring to a and not the 99 per se.
>b is another name for a, or b _refers_ to a (hence it is a reference). If
>you assign b to 4,
assign 4 to b
>a and b will equal 4,
Something like that.
>because a and b refer to the same value.
Refer to the same object.
>If you assign a to 4, a and b will again equal 4.
4 to a.
-- Greg Comeau / Comeau C++ 4.3.3, for C++03 core language support Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90. Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
- Next message: Greg Comeau: "Re: better understanding references"
- Previous message: Thomas Matthews: "Re: Optimizing a switch statement"
- In reply to: David White: "Re: better understanding references"
- Next in thread: David White: "Re: better understanding references"
- Reply: David White: "Re: better understanding references"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|