Christian Hackl
11/28/2008 1:38:00 PM
amit ha scritto:
> On Nov 28, 1:05 pm, Paavo Helde <pa...@nospam.please.ee> wrote:
>> amit <amitkee...@gmail.com> kirjutas:
>>
>> Yes, references cannot be reseated, that's a good thing about them. Also,
>> they are not objects in C++ sense, meaning that you cannot legally obtain
>> the address or size of the reference itself.
>>
> I am not sure if I agree. I got slightly confused.
> A reference is like a second name of the same object.
> when I do something like:
> A &objref = a1,
>
> it means the object has 2 names a1 and objref.
> So i should be allowd to get the address of objref and I should also
> be allowed to find the size and both should be same as a1.
>
> Fo example: I have 2 names, one my official name in official records
> and one my near and dear once call me. I will turn around if you call
> me by either of the names...
That's correct, but it does not contradict what Paavo said. "a1" and
"objref" are different names for the same object. Retrieving the address
or size of "objref" is the *same* as retrieving the address or size of "a1".
Consider it this way: the sheer fact that "objref" is a reference is
exposed by the language only at the place of its declaration. Once
you've established the reference, both names are completely equal in
their usage.
As for you real life example: I cannot make "amit" refer to a different
person once I've established that the name refers to you. Neither can I
do so with "a1" or "objref" in C++.
--
Christian Hackl