Thread overview
Bug in associative arrays?
Mar 13, 2004
Steve Adams
Mar 13, 2004
J C Calvarese
Mar 13, 2004
Steve Adams
Mar 14, 2004
Luke D
March 13, 2004
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
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
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
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.