Reply to Re: which language allows you to change an argument's value?

Your name:

Reply:


Posted by rolkA on 09/30/07 10:58

On 30 sep, 12:47, Summercool <Summercooln...@gmail.com> wrote:
> I wonder which language allows you to change an argument's value?
> like:
>
> foo(&a) {
> a = 3
>
> }
>
> ...
> is there any way to prevent a function from changing the argument's
> value?
> ...
> Is there a way to prevent it from happening in the
> languages that allows it?

Hi,
Of course in C++, functions that don't modify argument's value should
(i'd rather say MUST) wait for a CONST reference or a value :

// const ref
foo(const T& a) {
a = 3; // error

}
// value
foo(T a) {
a = 3; // ok, but modify only the formal parameter : the argument
(aka actual parameter) is not changed

}

Now if you want to prevent a function (from a library you are using)
to modify it... Erm well, you shouldn't : a good librairy will never
wait for a non-const argument if it doesn't need to be modified. So in
this case "Is there a way to prevent it from happening" is
unpertinent : you could copy the object, but if the purpose of the
fucntion was to modify it, it's pointless.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация