View Single Post
Old Apr 30th, 2005, 1:36 PM   #3
Eggbert
Professional Programmer
 
Eggbert's Avatar
 
Join Date: Nov 2004
Posts: 250
Rep Power: 5 Eggbert is on a distinguished road
>with MAJOR problems like being unable to be re-assigned and not being able to be NULL
These are two design decisions that affect the definition of a reference, not problems. Since a reference is a synonym for an existing object, what should a null reference represent? Since a reference is a synonym for an existing object, how do you propose re-assigning it? There are no operations on references, per se, only on the object referred to. If you can propose a non-ambiguous definition for re-assignable references and references to null, I have no doubt that the standards committee would be happy to hear it.

In my opinion, the only real problem with references is that references to references are illegal. Since a reference to a reference is clearly a reference, this limitation has been sent as a defect report, hopefully to be fixed in C++0x since it hinders flexible use of the standard library.

>but is it really useful?
I like to think so, though rather than thinking of references as a replacement for pointers, it would be better think of them as a supplement. If you know that an object will always be available (ie. never null), and the reference need not be assigned to, use a reference. Otherwise, use a pointer. You will find that they coexist quite nicely.
Eggbert is offline   Reply With Quote