www.digitalmars.com         C & C++   DMDScript  

D - Bug in associative arrays?

reply Steve Adams <adamss ascinet.com> writes:
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
next sibling parent reply J C Calvarese <jcc7 cox.net> writes:
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

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
parent Steve Adams <adamss ascinet.com> writes:
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.


Mar 13 2004
prev sibling parent Luke D <Luke_member pathlink.com> writes:
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