Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 30th, 2005, 1:48 AM   #1
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
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.
bl00dninja is offline   Reply With Quote
Old Apr 30th, 2005, 7:17 AM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 30th, 2005, 12:36 PM   #3
Eggbert
Professional Programmer
 
Eggbert's Avatar
 
Join Date: Nov 2004
Posts: 250
Rep Power: 4 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
Old Apr 30th, 2005, 5:21 PM   #4
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
thanks for the info
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:08 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC