We need an internal keyword.

Laurent Tréguier laurent.treguier.sink at gmail.com
Sun Oct 21 08:40:36 UTC 2018


On Sunday, 21 October 2018 at 03:17:23 UTC, 12345swordy wrote:
> So that classes can share some of their variables but not 
> others in a module.
>
> IE.
>
> class A
> {
> internal int A; //This is shared in the module
> private int B; // But not this.
> }
>
> No need to reintroduce the "Friend" feature from cpp.

This is by design; the D way of dealing with this would be to 
split the module into a package with multiple modules. The A 
class would be in its own module, and use `package` where you 
used `internal` so that other modules in the same package can 
have access to it.
Using a package.d package module 
(https://dlang.org/spec/module.html#package-module), you can 
still use the multiple modules just as if they were a single 
module.

Instead of a source tree like this:

source
|
+-some
   |
   +-thing.d

You'd end up with a source tree like this:

source
|
+-some
   |
   +-thing
     |
     +-package.d
     |
     +-a.d
     |
     +-rest_of_the_stuff.d

Where package.d publicly imports a.d and rest_of_the_stuff.d, so 
`import some.thing` would still work.


More information about the Digitalmars-d mailing list