Init const fixed-sixed array in ctor

bearophile bearophileHUGS at lycos.com
Fri Jun 17 18:18:14 PDT 2011


Jonathan M Davis:

Sure, it's a special case where setting that one element sets 
> the whole array, but making that work would be special casing for such an 
> array and complicate the compiler for little benefit.

Don't worry, I have defined the array of length one just because I like to minimize my examples :-)


> Now, if
> array = [c];
> doesn't work, _then_ we have a problem.

This doesn't compile, nor several variants of it:


struct Foo {
    const char[1] array;
    this(char c) {
        array = [c];
    }
}
void main() {}


Bye,
bearophile


More information about the Digitalmars-d-learn mailing list