In article <kj********************************@4ax.com>,
cppaddict <he***@hello.com> wrote:
I understand that there are a couple differences between reference
variables and pointer:
1) reference variables *must* be initialized.
2) You cannot change what a reference variable refers to.
My question is: In what situations is it better to use a reference
variable over a pointer?
Define "better". Does it mean "simpler syntax"? Then references are
better (fewer pesky &'s and *'s to worry about). Does it mean "having
things out in the open so you can see explicitly what's going on?" Then
pointers are better, because the &'s and *'s give you clues as to what's
likely to happen to the data.
Except for those situations that *require* one or the other, using
pointers versus references is basically a religious-type issue. I
personally prefer to use references unless I have to use pointers (e.g.
when I need to be able to change which object it refers to). Some people
have the opposite preference.
--
Jon Bell <jt*******@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA