On Thu, 30 Jan 2014 12:07:07 -0500, Cooler <kul...@hotbox.ru> wrote:
On Thursday, 30 January 2014 at 16:18:33 UTC, Steven Schveighoffer wrote:
void foo(int x)
{
x = 5;
}
"hey, why doesn't that work! Setting a parameter to another value
should be illegal!"
Difference is here.
"void foo(int x){}" - the caller will NEVER see any change to 'x'.
"void foo(int[] x){}" - the caller MAY or MAY NOT see changes to 'x'.
This is incorrect:
foo(int[] x){} - The caller will see changes to data 'x' references.
A slice is a reference type, it references a specific block of data. It's
more akin to a pointer than an int.
I could change my example:
void foo(int *x)
{
int n = 3;
x = &n;
}
"hey, why doesn't x now point to 3? Should be illegal!"
-Steve