OK, after our this long discussion, I am turned curious if there are any changes in the recent standards/compilers etc.
Just before I did a quick search on google search on "reference" and "reseating". The following showed up as result.
All of them show a reference can not be reseated. Though there are other links for forums on disucssing the same, I read them that all suggesting they can not be 'reseated' once initalized.
Now I am not sure what kind/standard of compiler are you using, and say, your compiler is wrong/obsolete or others (including myself) wrong. Check it out.
Check the link
http://www.stat.harvard.edu/ccr2005/C++/refs-ptrs.pdf
and in the Reference V (Page 5) it states:
1 2 3 4 5 6 7 8 9 10
|
• difference with C: in C++, pass by reference has a distinct meaning
• although there are big debates on this issue, here is some general advice on
when to use what while calling/writing a function:
• when to use references?
– use references when you can, and pointers when you have to
– references are usually preferred over pointers whenever you don’t need
re-initialization or ”reseating”
• when to use pointers?
– use a pointer when a function’s return value needs to be NULL to indicate
“failure” because you cannot return a NULL reference
|
"Once a reference is created, it cannot be later made to reference another object; we say it cannot be reseated. This is often done with pointers. " noted under "Relation to pointers" at
http://en.wikipedia.org/wiki/Reference_(C%2B%2B)
Check the point "reference type cannot be reseated in C++" at
http://meditation-art.blogspot.com/2007/04/reference-type-cannot-be-reseated-in-c.html
Check the point [8.5] named "How can you reseat a reference to make it refer to a different object?" at
http://yosefk.com/c++fqa/ref.html
And I never said, it should not be avoided. They can be avoided when they are not for the purpose. They should be used carefully.
Check it out. Good luck :)