associative arrays with arrays as value
MLT
none at anon.com
Sat Apr 18 12:27:10 PDT 2009
I am just learning D, and playing around. So I have no good reason why one would do the following, but I also don't understand why it doesn't work...
I was trying to make an associative array with int[5] as the value type. That didn't work properly. int[] did, and I don't understand why.
Here is what worked:
module main ;
import tango.io.Stdout ;
void main()
{
int[] [char[] ] x = [ "a":[1,2,3,4,5] ] ;
x["b"] = x["a"] ;
Stdout(x).newline ;
}
and here is what didn't:
void main()
{
int[5] [char[] ] x = [ "a":[1,2,3,4,5] ] ;
x["b"] = x["a"] ;
Stdout(x).newline ;
}
(Only diffence is the 5 in the int[5][ char[] ]x)
The error I get (with gdc) is: Error: cannot assign to static array x["b"]
I tried many other versions of the assignment x["b"][] =, x["b"]=[1,2,3,4,5], etc. But nothing work.
Why is that?
More information about the Digitalmars-d-learn
mailing list