|
Posted by Scott Gifford on 10/01/07 17:28
Summercool <Summercoolness@gmail.com> writes:
> I wonder which language allows you to change an argument's value?
[...]
> What about Java and Perl?
Perl will let you change the value of a passed-in object directly.
Others have already answered about Java.
> is there any way to prevent a function from changing the argument's
> value?
Make a copy of the object, and pass in the copy.
Without making a copy, of the languages I know, C++ comes closest to
supporting an unmodifiable argument passed by reference. Using a
const reference or const pointer indicates that the reference won't be
changed, but even that can be subverted by the function's author with
casting.
-----Scott.
Navigation:
[Reply to this message]
|