Quote:Original post by gharen2
You're overlooking the fact that you have multiple references to the same instance.
The reference returned by the get property is a separate reference to the same instance. If you change the retrieved reference to something else, the original reference inside the class will still point to the original instance.
In your example, I could retrieve a reference to sfFoo, and set that reference to null. However, the reference to sfFoo inside the Foo class is still intact.
In my opinion this makes the const keyword unnecessary.
I don't think you quite understand the purpose of const. It's not to guarantee that a particular area of memory will remain constant across a certain period of time. Rather, it forces a distinction between mutator and nonmutator methods, which turns out to be really useful for uncovering a variety of common logic errors.