On Friday, 29 November 2013 at 08:48:03 UTC, Chris Cain wrote:
On Friday, 29 November 2013 at 08:32:12 UTC, Cooler wrote:
...

Try making fill array look more like this:

void fillArray(ref string[int] a) { a[10] = "A"; }

The issue is that an array (and/or associative array) is a value type. Basically, you can look at it as a struct with a pointer (and some extra info). If you don't pass it as a ref then reallocations (such as what happens when you add an item to an empty AA) will cause the two to not point to the same information anymore.

But on the other hand, AA array is sometimes affected without ref parameter, so advice to put ref does not explain per se the issue.

Actually this is a good defficiency illustration of separation between value types and 'reference types' which are passed 'by reference'.

Reply via email to