Home

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.

previous
next

Re: Stream states questions
Re: pickle and __slots__
Is it bad to use references in these cases?
Re: deep copy of a polymorphic object with only a base ptr?
Re: Parameterize formatting string
kosmetyka samochodowa
skuteczne pozycjonowanie
konferencje nad morzem
manager piłkarski
Opakowania