On Monday, 1 September 2014 at 18:08:48 UTC, nikki wrote:
so I am still very new to structs and & and * adress and
pointer stuff, I have this basic code :
struct S {
int value = 0;
}
void func(S thing){
writeln(&thing); //BFC52B44
thing.value = 100;
}
S guy = {value:200};
writeln(&guy); //BFC52CCC
func(guy);
writeln(guy.value);// this prints 200, because the adress
was not the same
I think I see whats going on but I don't know how to fix it?
void func(ref S thing){
writeln(&thing);
thing.value = 100;
}
The ref keyword passes the variable into the function by
reference, so that it is not copied.