How to create friends of a class at compile time?

Tejas notrealemail at gmail.com
Thu Jul 15 18:24:25 UTC 2021


On Thursday, 15 July 2021 at 18:06:26 UTC, Steven Schveighoffer 
wrote:
> On 7/15/21 1:43 PM, Tejas wrote:
>
>> How do you write the equivalent of that in D? Is the answer 
>> still the same? Manually keep it in the same module, or is 
>> there a programmatic way of converting this to D?
>
> Functions in the same module can access `private` members. 
> Functions in the same package (or in whatever package you 
> specify) can access `package` members. That is how D does 
> "friends".
>
> So the answer to your question depends on how the C++ code is 
> organized.
>
> It's always possible that something in C++ here is not 
> translatable into D, but most likely can be redesigned (and 
> likely better designed).
>
> -Steve

Yes, it seems like seperating chunks of C++ code into seperate 
modules and using the
```d
package(qualifiedIdentifier)
```
access specifier seems to be the way to go.

Was wondering if there was some wizardry that the veterans knew 
that would make it less difficult, but it seems this is the only 
way.

Thank you very much for replying!


More information about the Digitalmars-d-learn mailing list