D - Bug in associative arrays?
- Steve Adams (13/13) Mar 13 2004 It looks like you can't have an associative array on strings?
- J C Calvarese (8/27) Mar 13 2004 You should get the desired result if you declare it like so:
- Steve Adams (2/35) Mar 13 2004
- Luke D (4/17) Mar 13 2004 No, it's not a bug, you would have an array of chars, not of strings. I...
It looks like you can't have an associative array on strings? int main() { char[char[]] a; a["aa"] = "bb"; return( 0 ); } gives an error of: z.d(4): cannot implicitly convert char[2] to char If this were: int[char[]] a; a["aa"] = 1; it works okay.
Mar 13 2004
Steve Adams wrote:It looks like you can't have an associative array on strings? int main() { char[char[]] a;You should get the desired result if you declare it like so: char[] [char[]] a;a["aa"] = "bb"; return( 0 ); } gives an error of: z.d(4): cannot implicitly convert char[2] to charThat's what was happening. The compiler thought you were trying to assign "aa" (char[2]) to a char[1] variable.If this were: int[char[]] a; a["aa"] = 1; it works okay.-- Justin http://jcc_7.tripod.com/d/
Mar 13 2004
That did it, thanks. J C Calvarese wrote:Steve Adams wrote:It looks like you can't have an associative array on strings? int main() { char[char[]] a;You should get the desired result if you declare it like so: char[] [char[]] a;a["aa"] = "bb"; return( 0 ); } gives an error of: z.d(4): cannot implicitly convert char[2] to charThat's what was happening. The compiler thought you were trying to assign "aa" (char[2]) to a char[1] variable.If this were: int[char[]] a; a["aa"] = 1; it works okay.
Mar 13 2004
No, it's not a bug, you would have an array of chars, not of strings. It should be written as char[][char[]] a. Luke D In article <40538411.7020500 ascinet.com>, Steve Adams says...It looks like you can't have an associative array on strings? int main() { char[char[]] a; a["aa"] = "bb"; return( 0 ); } gives an error of: z.d(4): cannot implicitly convert char[2] to char If this were: int[char[]] a; a["aa"] = 1; it works okay.
Mar 13 2004