On Thursday, 7 March 2024 at 22:18:40 UTC, Richard (Rikki) Andrew Cattermole wrote:
There are two ways to do this.

1. Use templates. https://tour.dlang.org/tour/en/basics/templates

Thank you for teaching me how to do this. This is where I first learned to use templates in D, and I have been using them since for functions, and as of yesterday, my first mixin template.

That being said, I'm pleased to announce the return of the `Map` class. As of yesterday's commit, the class template `class MapTemp(TileType:Tile, UnitType:Unit)` and `interface Map` have now been replaced with a single `Map` class as they were before.

At the time I had asked about this, I had not yet discovered that an array of objects can be filled with objects of a derived type by just using the regular cast syntax. Now that I know this, I've decided to just create the objects under the `VisibleTile` and `VisibleUnit` classes, place them in the `Map` object's arrays (cast to `Tile` and `Unit`), and then cast them back whenever I need to access anything specific to the derived classes.

Now I no longer have to deal with the limitations of interfaces. Things should be easier now.

The straw that broke the camels back was when I made my first mixin template, which adds functionality to a class for manipulating arrays of `Unit` objects. The compiler wasn't allowing it in the `Map` class because the array that I was trying to give it access to was of `UnitType`, not specifically the base `Unit` class. I'm happy to have it back.
  • Re: Can a D libr... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
    • Re: Can a D... Liam McGillivray via Digitalmars-d-learn
      • Re: Can... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
        • Re:... Liam McGillivray via Digitalmars-d-learn
          • ... cc via Digitalmars-d-learn
            • ... Liam McGillivray via Digitalmars-d-learn
            • ... Liam McGillivray via Digitalmars-d-learn
              • ... Liam McGillivray via Digitalmars-d-learn
              • ... Liam McGillivray via Digitalmars-d-learn
              • ... cc via Digitalmars-d-learn
    • Re: Can a D... Liam McGillivray via Digitalmars-d-learn

Reply via email to