Why D doesn't have constant function arguments?
Dan
murpsoft at hotmail.com
Tue Apr 3 12:30:20 PDT 2007
> > I think that 'inout' could be used in place of C++'s const references, but how does it work? Is this a masked pointer or something?
> AFAIK 'inout' is similar to C++ passing by reference.
> > Or maybe this is done the other way? The D Way?
> > Thanks in advance.
It's not really a reference. It's really just that instead of:
int f1(int x){ <-- makes a copy of x, puts it on the stack
x += 3; <-- affects the copy on the stack, not the original
return x;
}
int f2(inout int x){ <-- does not copy the data, uses the original register or memory location.
x += 3; <-- affects the original
return x;
}
That's the difference.
More information about the Digitalmars-d-learn
mailing list