![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
references vs. pointers
in my microscopic experience with C++ i am wondering how much REAL programmers (like IR and eggbert) actually use references as opposed to pointers. it seems so limiting to have references with SLIGHTLY cleaner syntax with MAJOR problems like being unable to be re-assigned and not being able to be NULL. do you guys really use them? i understand it's a little better than using parens and asterisks all over the goddamn place but is it really useful? examples would be nice. the way my ignorant mind sees it now is "fuck references" use pointers. is it really better?
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
I'm no expert, but I guess it means they won't cause weird memory errors and crash the program - always a good thing, IMO.
|
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: Nov 2004
Posts: 250
Rep Power: 4
![]() |
>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. ![]() |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
thanks for the info
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|