difficulty with rectangular arrays

Moth postmaster at gmail.com
Fri Jun 11 08:30:29 UTC 2021


hullo all. i've encountered a bizzare inconsistency.

the following is the [D spec on rectangular 
arrays](https://dlang.org/spec/arrays.html#rectangular-arrays):

```
void main()
{
     import std.stdio: write, writeln, writef, writefln;
     double[6][3] matrix = 0; // Sets all elements to 0.
     writeln(matrix); // [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], 
[0, 0, 0, 0, 0, 0]]
}
```


however, when i attempt to place the very same code within a 
class...

```
class ExampleClass
{
     double[6][3] matrix = 0; //fails to compile - "Error: cannot 
implicitly convert expression `0` of type `int` to `double[6][3]`"
}
```

evidently i'm doing something wrong here, but i can't understand 
what or why. what's going on? have i misread the spec?



More information about the Digitalmars-d-learn mailing list