Boost logo

Boost :

From: Noel Yap (Noel.Yap_at_[hidden])
Date: 2003-05-03 20:28:35


Floris van den Berg wrote:
> > Like I said before, references are implicitly dereferenced pointers.
>
> You are confusing language implementation with language definition.

Implementation aside, do or don't references act like implicitly
derefenced pointers? Perhaps I shouldn't've used a metaphor above.

> The
> definition says a reference is an alias, meaning you don't check the
> existance of the passed object. You don't have to check it because the
> caller takes responsibility that the object in fact exists. There are
> probably tons of ways to abuse references and to break the system, but
> that's with every system. For example you can break use of const just as
> easily via const_cast. That a reference is implemented as a pointer is just
> a side effect that should be ignored for argument's sake.

Yes, a reference is an alias. OTOH, the fact that this is the
definition implies that it will act like an implicitly dereferenced
pointer. I just prefer to think of it the other way around (so there's
less memorization involved) -- if a reference is an implicitly
dereferenced pointer, it must be an alias to an existing object,
regardless of how that object is allocated.

Noel


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk