array as parameter
monarch_dodra via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jun 7 14:17:40 PDT 2014
On Saturday, 7 June 2014 at 20:56:14 UTC, Paul wrote:
> Dynamic array is really reference. Right? But why modification
> of parameter in this case does not work:
>
> void some_func(string[] s) {
> s ~= "xxx"; s ~= "yyy";
> }
>
> but this works:
>
> void some_fun(ref string[] s) {
> s ~= "xxx"; s ~= "yyy";
> }
>
> In the 1st case s is reference too, is not it?
It's a value type that holds a reference to data. If you modify
the *actual* slice, rather than the referenced items, then you
need to pass by ref.
More information about the Digitalmars-d-learn
mailing list