char[][] titles = (" ", "C", "!", "Description", "Resource", "In Folder", "Location","foo" );

Bill Baxter dnewsgroup at billbaxter.com
Fri Feb 29 22:47:46 PST 2008


Ty Tower wrote:
> The line below will not compile 
> 
> char[][] titles = (" ", "C", "!", "Description", "Resource", "In Folder", "Location","foo" );
> 
> The error is
> 
> cannot implicitly convert expression ("foo") of type char[3u] to char[][]
> 
> Is it accepting the first 7 and rejecting the last or does it start from the last in the compiler?
> How do I fix this?
> 

First it's [..] not (..) for array literals.
Second, current D behavior is to take the type from the first element, 
rather than doing something useful like figuring out the best type that 
can hold all the elements.

So you have to tell it you want it to be a list of dynamic arrays by 
making the first one a dynamic array:

char[][] titles = [" "[], "C", "!", "Description", "Resource", "In 
Folder", "Location","foo" ];

I think that does it.  If not maybe you have to use the [] on all of the 
strings.  I don't recall.


--bb


More information about the Digitalmars-d-learn mailing list