Reference to an object disregarding mutation - what's the trick?
BCS
ao at pathlink.com
Mon May 28 10:50:54 PDT 2007
Reply to Steve,
> OK, so I'm in a typical tree situation:
>
> int n = node.parent.nodelist.length;
> node.parent.nodelist.length = n+1;
> // p.s. why can't I say node.parent.nodelist.length++ - doesn't
> work
> // other fluff with node.parent.nodelist
> node.parent.nodelist[n] = x;
> For brevity I want to be able to say:
> Node[] t = node.parent.nodelist;
> int n = t.length;
> t.length = n+1;
> .....
> But as soon as I modify t it becomes a separate object.
>
> OK, I can use with, but how do I get the semantics I'd get with a
> plain old pointer to the object?
>
you may be running into the issue that changing an array length can cause
it to reallocate. I'd have to see more implementation to give you more useful
information.
More information about the Digitalmars-d
mailing list