quote:Original post by rypyr
"just learn to code properly"...that''s a good one...
If you dislike references so much, don''t use them, it''s that simple. You don''t need to get upset about them.
However, the main argument for references is to ensure that what you''re "pointing at" is valid and not NULL. It''s very hard to get around this if you''re using references.
If you don''t accept that argument, the only other ones I can think of are: 1) it''s easier to declare a const reference (i.e. a pointer to an object that you cannot modify) than it is for pointers and 2) you can still use the dot notation with references.
Generally, when programming interfaces, it is better to use const references wherever possible.
Regards,
Jeff
From the link that was posted earlier
"Some people take the fact that a reference can''t be null to mean that references are somehow safer than pointers. They may be a little safer, but I don''t think they''re a lot safer. Although a valid reference can''t be null, an invalid one can be null. In fact, there''s a ton of ways programs can produce invalid references, not just null references. For example, you can define a reference so that it refers to the object addressed by a pointer, as in:
int *p;
...
int &r = *p;
If the pointer happens to be null at the time of the reference definition, the reference is a null reference. Technically, the error is not in binding the reference, but in dereferencing the null pointer. Dereferencing a null pointer produces undefined behavior, which means lots of things could happen, and most of them aren''t good. It''s likely that, when the program binds reference r to *p (the object that p points to), it won''t actually dereference p. Rather, it will just copy the value of p to the pointer that implements r. The program will keep running only to have the error manifest itself more overtly sometime later during program execution. Oh joy."