Java like class importing
Walter Bright
newshound2 at digitalmars.com
Sun Nov 17 22:31:27 UTC 2019
On 11/17/2019 1:03 AM, tcak wrote:
> I started working on a project which contains many classes in it. One of them is
> name "SpacePosition" which holds x and y position, and a method "distance".
> Distance is defined as both instance method and class method. So I can call it
> like,
>
> SpacePosition.distance( pos1, pos2 );
>
> After defining many classes in the my main.d file, I wanted to separate the
> classes into separate files. I created a new file with the name
> "SpacePosition.d" and put the class into it.
>
> In the main.d, I added the line "import SpacePosition;". And when I compile the
> main.d, BAM!
>
> Error: undefined identifier distance in module SpacePosition
>
> So you have to import it like "import SpacePosition: SpacePosition;" or call the
> method like "SpacePosition.Spaceposition.distance( pos1, pos2 )".
The usual D practice is to call the module "spaceposition.d" that contains
"SpacePosition".
More information about the Digitalmars-d
mailing list