C++: define a reference always reference the same object# Programming - 葵花宝典
i*p
1 楼
How can I define a reference to ensure it will always reference the same
object but you can use the reference to modify the object's values?
The follow FAQ says a reference is always const. Do you agree it?
http://www.parashift.com/c++-faq-lite/const-correctness.html
...
[18.7] Does "Fred& const x" make any sense?
No, it is nonsense.
To find out what the above declaration means, you have to read it right-to-
left. Thus "Fred& const x" means "x is a const reference to a Fred". But
that is redunda
object but you can use the reference to modify the object's values?
The follow FAQ says a reference is always const. Do you agree it?
http://www.parashift.com/c++-faq-lite/const-correctness.html
...
[18.7] Does "Fred& const x" make any sense?
No, it is nonsense.
To find out what the above declaration means, you have to read it right-to-
left. Thus "Fred& const x" means "x is a const reference to a Fred". But
that is redunda