multidimensional array
JKPdouble via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Sep 27 21:40:59 PDT 2014
On Sunday, 28 September 2014 at 04:38:56 UTC, JKPdouble wrote:
> On Sunday, 28 September 2014 at 04:24:25 UTC, Joel wrote:
>> I'm trying to make a multidimensional array. I feel I've tried
>> every thing. Is there a good guide explaining it?
>>
>> struct Spot { bool dot; }
>> spots = new Spot[][](800,600);
>> assert(spots[800-1][600-1].dot, "Out of bounds");
>
> dot is initialized to false, then the assertion fails. But your
> assertion message leads to think that there is a bound error,
> which is not the case, the
> assertion fails because you're expecting dot to be true:
>
> ----
> import std.stdio;
>
> void main(string args[])
> {
> struct Spot { bool dot; }
> auto spots = new Spot[][](800,600);
>
> writeln(spots);
> assert(!spots[800-1][600-1].dot, "Out of bounds");
> }
> ----
>
> passes without failure. Actually the array size is OK.
I meant:
----
void main(string args[])
{
struct Spot { bool dot; }
auto spots = new Spot[][](800,600);
assert(!spots[800-1][600-1].dot, "element dot is true");
}
----
More information about the Digitalmars-d-learn
mailing list