`clear`ing a dynamic array
anonymous via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Oct 24 06:31:02 PDT 2015
On 24.10.2015 15:18, Shriramana Sharma wrote:
> int a[] = [1,2,3,4,5];
Aside: `int[] a;` is the preferred style for array declarations.
> How to make it so that after clearing `a`, `b` will also point to the same
> empty array? IOW the desired output is:
>
> [1, 2, 3, 4, 5]
> [1, 2, 3, 4, 5]
> []
> []
>
> ... and any further items added to `a` should also reflect in `b`.
>
You can't do that with built-in arrays. The length of a dynamic array is
a value member of the array structure. So to update `b`'s length you
need access to the actual `b`.
More information about the Digitalmars-d-learn
mailing list