Thread overview | ||||||
---|---|---|---|---|---|---|
|
March 13, 2004 Bug in associative arrays? | ||||
---|---|---|---|---|
| ||||
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. |
March 13, 2004 Re: Bug in associative arrays? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steve Adams | 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 char That'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/ |
March 13, 2004 Re: Bug in associative arrays? | ||||
---|---|---|---|---|
| ||||
Posted in reply to J C Calvarese | 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 char
>
> That'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.
>
>
>
|
March 14, 2004 Re: Bug in associative arrays? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steve Adams | 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. |
Copyright © 1999-2021 by the D Language Foundation