Error when using `import`.

Paul Backus snarwin at gmail.com
Sun Feb 25 03:23:03 UTC 2024


On Saturday, 24 February 2024 at 10:31:06 UTC, Liam McGillivray 
wrote:
>
> `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?

You can't give a class the same name as the file it's in. If you 
do, then when you try to use it from another file, the compiler 
will get confused and think you're referring to the file instead 
of the class (that's what "import is used as a type" means).

The easiest way around this is to change the name of the file to 
lower case. So, for example, you could change the name of the 
file with the `Unit` class in it to `unit.d`, and then write 
`import unit;` to access it from your other files.


More information about the Digitalmars-d-learn mailing list