How to implement private constructor

bauss jj_1337 at live.dk
Mon Apr 25 07:19:31 UTC 2022


On Monday, 25 April 2022 at 07:18:44 UTC, bauss wrote:
> On Monday, 25 April 2022 at 00:18:03 UTC, Vinod K Chandran 
> wrote:
>> Hi all,
>> Please take a look at this code. Is this the right way to use 
>> private constructors ?
>> ```d
>> class Foo {
>>     int p1 ;
>>     string p2 ;
>>     bool p3 ;
>>
>>     private this(int a, string b, bool c) {
>>         this.p1 = a
>>         this.p2 = b
>>         this.p3 = c
>>     }
>>
>>     this(int a) {
>>         this(a, "some string", true);
>>     }
>>
>>     this(int a, string b) {
>>         this(a, b, true);
>>     }
>> }
>> ```
>
> Yes and in addition to Ali's message then remember it's private 
> for the module only.

Oops typo.

What I meant is that private is module level, so it's __not__ 
private in the module, but it is for other modules.


More information about the Digitalmars-d-learn mailing list