Insert an element into an Associative Array ?

Jacob Carlborg doob at me.com
Wed Apr 4 12:33:48 PDT 2012


On 2012-04-04 20:57, Chris Pons wrote:
> I'm playing around with associative arrays right now and I can't
> seem to figure out how to add additional objects to the array. I
> tried insert but it doesn't recognize both arguments.
>
> Also, if I do this it produces an error:
>
> Node[bool] test;
>
> Node node;
>
> Node[bool] temp = [ false:node ];
>
> test ~= temp;
>
>
> Error 1 Error: cannot append type Node[bool] to type
> Node[bool] C:\Users\CP\Documents\Visual Studio
> 2010\Projects\D\STDS\NPC.d 256
>
> Does this mean you can't use the append operator on associative
> arrays ? ( this one ~= ) ?

Yes, since for an associative array you need to add both a key and a 
value. The syntax used is this:

aa[key] = value;

i.e.

test[false] = node;

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list