On Sunday, 12 June 2022 at 05:05:46 UTC, forkit wrote:
Is it possible to create a package.d, consisting of (for example), two modules, where each module can access private declarations within each other.

For this to be possible: You must first collect all modules in the directory with the same name as the module. Then you have to declare them with public import in package.d. If there are module specific things, you isolate them with package. Finally, compile it like this:

dmd main myproject/mymodule

**main.d for example**
```d
import myproject.mymodule;

void main()
{
  S s;  // ok
  //P p // Error: undefined identifier `P`
  auto p = packageTest(); //ok
}
```
---

**package.d for example**
```d
module myproject.mymodule;

public
{
  import myproject.mymodule.module1;
  import myproject.mymodule.module2;
  import myproject.mymodule.module3;
}
```
---

**module1.d for example**
```d
module myproject.mymodule.module1;

struct S
{
  int i;
}

auto packageTest()
{
  return P();
}

package
{
  struct P
  {
    int i;
  }
}
```

SDB@79

Reply via email to