Array declaration warning
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jun 3 13:33:02 PDT 2015
On 06/03/2015 01:28 PM, 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);
I don't think you need the empty [] there. pathList[n] is one of the
paths and you are adding a coordinate to it:
pathList[n] ~= CoOrd(cX, cY);
> 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)...
I makes perfect sense! ;) pathList[NumPaths-1] is the last path and you
are accessing the last coordinate in it. C did it wrong. Luckily, I've
always found C's syntax unbelievably backward (or inside-out?).
Ali
More information about the Digitalmars-d-learn
mailing list