multidimensional array

JKPdouble via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Sep 27 21:38:55 PDT 2014


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.



More information about the Digitalmars-d-learn mailing list