On Monday, 13 August 2018 at 12:34:25 UTC, Andrey wrote:
Hello,

This is my test project:
source/app.d
source/MyClass.d

app.d:
------------------------------------------------
import std.stdio;
import MyClass;

void main(string[] args)
{
MyClass.MyClass.parse(args); // I want just MyClass.parse(args);
}
------------------------------------------------

MyClass.d
------------------------------------------------
import std.stdio;

struct MyClass
{
    static void parse(string[] args)
    {

    }
}
------------------------------------------------

In "main" function I need to write "MyClass.MyClass.parse(args)" bit I want just "MyClass.parse(args)". If I do so then I have an error:
Error: undefined identifier parse in module MyClass.

Of course function "parse" doesn't exist in this module. But it exists inside struct "MyClass"!
What should I do to import my struct correctly?

That's just name collision, because module is a valid symbol you need to be specific about what you are trying to access.

Try selective import instead

  import MyClass : MyClass;

Of course if there is more symbols needed you have to specify them as well after a comma.


Another option to save up on typing is renamed imports

  import mc = MyClass;

  mc.MyClass.parse(...)

Reply via email to