Clearing associative array.

ciechowoj via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Mar 12 04:34:16 PST 2016


Could someone explain to me, why following code does not compile?

int main()
{
	string[string] x = [ "foo" : "bar" ];
	x.clear();
	x = [];

	return 0;
}

Errors:
main.d(7): Error: no property 'clear' for type 'string[string]'
main.d(8): Error: cannot implicitly convert expression ([]) of 
type void[] to string[string]
Failed: ["dmd", "-v", "-o-", "main.d", "-I."]

If above doesn't work how am I supposed to clear the array? `x = 
string[string].init;` is somewhat ugly.

dmd --version
DMD64 D Compiler v2.070.0
Copyright (c) 1999-2015 by Digital Mars written by Walter Bright



More information about the Digitalmars-d-learn mailing list