Problems with Array Assignment?
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed May 10 06:43:54 PDT 2017
In your code, I see one big mistake:
---
class TileRenderer
{
private Tile[] tiles;
/*...*/
}
class CTileRenderer : TileRenderer
{
private CTile[] tiles;
/*...*/
}
---
Those are two separate arrays! Stuff examined through
TileRenderer will be looking at a different array than looking
through CTileRenderer.
I would just remove the `tiles` variable from the subclass and
only use the base class one. I think that will work for you.
writeTiles can do if(auto ctile = cast(CTile) tile) in the loop
to get to the more specific class (or you might refactor your
interfaces a bit. Really, I'd say `render` should just be a
method in Tile, which its own subclasses can override.)
More information about the Digitalmars-d-learn
mailing list