User Tools

Site Tools


hpl2:amnesia:script_language_reference_and_guide:functions_-_part_3

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
hpl2:amnesia:script_language_reference_and_guide:functions_-_part_3 [2013/03/28 01:51]
thegreatcthulhu
hpl2:amnesia:script_language_reference_and_guide:functions_-_part_3 [2013/03/28 02:05]
thegreatcthulhu [Do Reference Parameters Play a Role When Overloading Functions?]
Line 234: Line 234:
 ==== Do Reference Parameters Play a Role When Overloading Functions? ==== ==== Do Reference Parameters Play a Role When Overloading Functions? ====
  
-Yes they do, but in a //specific way//, and with a few //​caveats//​. Essentially,​ adding a reference modifier to a parameter changes its //type//. E.g., ''​int''​ is the integer type, while ''​int&​ out''​ is an "​integer reference"​ type. Reference types are //only allowed// as function parameters though. Now, although the different reference modes (in, out, inout) behave differently,​ as far as the compiler is concerned, all of them give the same function signature. In its eyes, ''​string&'',​ ''​strint& in''​ and ''​strint& out''​ are the same when it comes to deciding which overload to call.+Yes they do, but in a //specific way//, and with a few //​caveats//​. Essentially,​ adding a reference modifier to a parameter changes its //type//. E.g., ''​int''​ is the integer type, while ''​int&​ out''​ is an "​integer reference"​ type. Reference types are //only allowed// as function parameters though. Now, although the different reference modes (in, out, inout) behave differently,​ as far as the compiler is concerned, all of them give the same function signature. In its eyes, ''​string&'',​ ''​string& in''​ and ''​string& out''​ are the same when it comes to deciding which overload to call.
  
 For this reason, except for some special cases and unless you take some special actions, the compiler often won't be able to decide which overload you intended to make the call to. This is why you generally shouldn'​t overload a function simply by providing another version which uses reference parameters. For this reason, except for some special cases and unless you take some special actions, the compiler often won't be able to decide which overload you intended to make the call to. This is why you generally shouldn'​t overload a function simply by providing another version which uses reference parameters.
hpl2/amnesia/script_language_reference_and_guide/functions_-_part_3.txt ยท Last modified: 2013/03/28 02:05 by thegreatcthulhu