The import keyword, which we have used in almost every program so far, is for introducing a new module to the current module:

import std.stdio;

The module name may contain the package name as well. For example, the std. part above indicates that stdio is a module that is a part of the std package.

The animal.cat and animal.dog modules would be imported similarly. Let’s assume that the following code is inside a file named “deneme.d”:

module deneme; // the name of this module

import animal.cat; // a module that it uses
import animal.dog; // another module that it uses

void main() {
    auto cat = new Cat();
    auto dog = new Dog(); 
}

Note: As described below, for the program to be built correctly, those module files must also be provided to the linker.

More than one module can be imported at the same time:

import animal.cat, animal.dog;

Selective imports

Instead of importing a module as a whole with all of its names, it is possible to import just specific names from it.

Get hands-on with 1200+ tech skills courses.