Error with associative array initializer
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Sat Jun 30 07:41:51 PDT 2007
Peter Neubauer wrote:
> I'm trying to initialize an associative array with key int and value type char[] like this:
>
> char[][int] stuff = [
> 0: "abc",
> 1: "def",
> 2: "ghi"
> ];
>
> ... which works just fine as long as the strings are all of equal length. For the following code:
>
> char[][int] stuff2 = [
> 0: "ab",
> 1: "def",
> 2: "ghi"
> ];
>
> results in the error message "cannot implicitly convert expression ("def") of type char[3] to char[2]". Just the same thing happens if the first value in the array is of greater length than the others. It all depends on the first string. How can I avoid this?
Make sure the type of the first expression is a dynamic array. "ab"[] or
cast(char[])"ab" would work.
More information about the Digitalmars-d-learn
mailing list