Array declaration warning

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 3 13:38:53 PDT 2015


On Wednesday, 3 June 2015 at 20:28:57 UTC, Paul wrote:
> Ooops, this is what I meant to post:
>
> struct CoOrd
> {
> 	int x, y;
> }
>
> CoOrd[][NumPaths]pathList;
>
>
> I append values like so...
>
> pathList[][n] ~= CoOrd(cX, cY);

The "[]" does nothing here. You can leave it (or add more) out 
without changing the meaning:

pathList[][n] ~= CoOrd(cX, cY);
pathList[n] ~= CoOrd(cX, cY);
pathList[][][n] ~= CoOrd(cX, cY);

... all the same.

> But to get the expected values, I need to access them like this 
> example for last x co-ord of last item:
>
>
> int xx = pathList[NumPaths-1][$ - 1].x;
>
>
> Doesn't seem right (but it works)...

Declarations are right to left, accesses are left to right. 
NumPaths is on the right in the declaration, and it's on the left 
in the access. Makes sense to me.


More information about the Digitalmars-d-learn mailing list