Array is already defined

Jonathan M Davis newsgroup.d at jmdavisprog.com
Fri Jan 5 15:28:58 UTC 2018


On Friday, January 05, 2018 15:22:49 Vino via Digitalmars-d-learn wrote:
> Hi All,
>
>   Request your help on how to unset or delete an array, in the
> below example, we get an error "Common  is already defined".
>
> Auto fn1 () {
> Array!string Text;
> Array!string Number;
> return tuple(Text, Number);
> }
>
> Void main () {
> static foreach(i; 0 .. 2) {
> typeof(fn1()[i]) Common;
> writeln(Common[]);
> Common.delete or Common.Unset // Something similar like this
> }
>
> From,
> Vino.B

static foreach does not create a new scope (if it did, it wouldn't work very
well at module or class/struct scope). If you declare any variables inside a
static foreach, give it an extra set of braces.

- Jonathan m Davis



More information about the Digitalmars-d-learn mailing list