I am trying to make a tactical role-playing game which I am likely to open-source. Right now the code is very simple, with only 3 files each containing a class with the same name.

The files are `Map.d`, `Tile.d`, and `Unit.d`. Each of these files contains an `import` line to access one of the others. I got the following errors when trying to compile all 3 files with DMD, and the same errors after switching to DUB.

```
source/Unit.d(6,17): Error: import `Unit.Map` is used as a type
source/Unit.d(16,5): Error: import `Unit.Map` is used as a type
source/Tile.d(9,15): Error: import `Tile.Unit` is used as a type
source/Map.d(6,22): Error: import `Map.Tile` is used as a type
source/Map.d(19,11): Error: import `Map.Tile` is used as a type
```

I thought that the circular chain of imports may be the problem, but removing all references to `Unit` in `Tile.d` did not fix the problem.

Here are the contents of Tile.d:
```
import Unit;

class Tile
{
        private bool allowStand = true;
        private bool allowFly = true;
        public int stickyness = 0;
        
        public Unit* occupant;
        
        bool allowUnit(bool isFlyer) {
                if (isFlyer) return this.allowFly;
                else return this.allowStand;
        }
}
```

`Unit.d` & `Map.d` are longer files. `Map.d` begins with `import Tile;`, and `Unit.d` begins with `import Map;`.

Why are the errors happening? What's the problem? Why is it `currentclass.importedclass` instead of simply the imported class?
  • Error when using... Liam McGillivray via Digitalmars-d-learn
    • Re: Error w... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
      • Re: Err... Liam McGillivray via Digitalmars-d-learn
        • Re:... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
    • Re: Error w... Paul Backus via Digitalmars-d-learn
      • Re: Err... Liam McGillivray via Digitalmars-d-learn
        • Re:... Liam McGillivray via Digitalmars-d-learn
          • ... Steven Schveighoffer via Digitalmars-d-learn
            • ... Liam McGillivray via Digitalmars-d-learn
              • ... Liam McGillivray via Digitalmars-d-learn
                • ... Danilo via Digitalmars-d-learn

Reply via email to