March 07, 2008 AA of static array | ||||
---|---|---|---|---|
| ||||
DMD v2.012, Windows
I am trying to use an Associative Array whose data type is a static array and key type is a string. The declaration and initialization of the array compiles, but fails with an out of bounds error. If I wrap the static array inside a struct, it works fine. Here is the code that fails...
void main()
{
alias int[5] S;
S[string] foo;
foo["abc"] = [1,2,3,4,5]; // out of bounds!
foo["qwerty"] = [9,8,7,6,5];
}
And here is code that works but is kludgy...
void main()
{
struct S
{
int[5] v;
}
S[string] x;
x["abc"] = S([1,2,3,4,5]);
x["qwerty"]= S([9,8,7,6,5]);
}
Have I coded the first example incorrectly or is this a bug?
--
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell
|
March 14, 2008 Re: AA of static array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | 在 Fri, 07 Mar 2008 21:39:21 +0800,Derek Parnell <derek@psych.ward> 写道:
> void main()
> {
> alias int[5] S;
> S[string] foo;
> foo["abc"] = [1,2,3,4,5]; // out of bounds!
> foo["qwerty"] = [9,8,7,6,5];
> }
use alias int[] S instead.
regards!
|
Copyright © 1999-2021 by the D Language Foundation