Simon:
a
reference is just a
pointer to the Object.
The Object lies somewhere in memory.
The closest analogy I can give is say Object is represented
like a City. A reference is the route you follow to get to
that City. Also,
you should now realise that you can have
many routes to reach a City. Similarly, there can be many
references to an Object.
Having said that Object is a City and reference is a route, we see what is happening in the code abv:
Code 1:
btn route is created and it points to the
City GoodButton.
Then a call to the replacer() is made.
As you know, we will pass a copy of the
btn route to the function.
Now the function takes this replaceMe route
and points it to a new City Evil and returns.
However, please note that our original btn route and GoodButton City are not changed.
Code 2:
tf route is created and points to a City Yin.
Then we make call to the changer() function with a copy of the route calling the copied route as changeMe. Now since, route changeMe is a copy of route tf, it still points to the city Yin. Using this changeMe route, I reach the city Yin and change its name to Yang. So, now the Yin city name has changed to Yang. Then return.
After returning, we use the route tf to goto the city. And to our surprise find that the name of the city has changed from Yin to Yang, but still it is the same City.
All others, am I anywhere close.....
just imagining stuff.....pretty boring afternoon for me here, so trying to be creative.....
Regds.
- satya
[This message has been edited by Madhav Lakkapragada (edited January 10, 2001).]