why no implicit convertion?
spir
denis.spir at gmail.com
Wed Nov 17 13:54:50 PST 2010
On Wed, 17 Nov 2010 22:10:19 +0100
Matthias Pleh <sufu at alter.com> wrote:
> void foo(char[] a) {}
> void bar(char[][] b) {}
>
> int main(string[] args)
> {
> char[4] a;
> char[4][4] b;
> foo(a); // OK: implicit convertion
> bar(b); // Error: cannot implicitly convert
> // char[4u][4u] to char[][]
> }
>
> what is the reason for the different behaviour?
> What's best to pass such multidimensional arrays?
I may be wrong, but it seems (also from main's signature) you're trying to apply plain C point-of-view to a D feature (dyn array).
Also, maybe what you need is an array of strings?
Finally, to initialise a dynamic array at a given dimension, you may use the idiom
string[] strings = new string[dim];
(but this does not work for 2 dimensions, I guess)
Sorry if I'm wrong and this does not help.
Denis
-- -- -- -- -- -- --
vit esse estrany ☣
spir.wikidot.com
More information about the Digitalmars-d-learn
mailing list