Re: How to disable/hide constructor when using factory method?

2019-01-24 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 24 January 2019 at 12:58:15 UTC, JN wrote: Doh. Of course. I feel so dumb. I just had it at @disable this();, then replaced @disable with private without thinking to add {} Give me a nickel for every time I've made an edit like that...!

Re: How to disable/hide constructor when using factory method?

2019-01-24 Thread JN via Digitalmars-d-learn
On Thursday, 24 January 2019 at 12:52:47 UTC, Arafel wrote: You are declaring the constructor, but not defining it, i.e. you're telling the compiler that it's in some other compilation unit. The compiler won't complain, but the linker will. If you replace: [...] with: [...] it should

Re: How to disable/hide constructor when using factory method?

2019-01-24 Thread Arafel via Digitalmars-d-learn
You are declaring the constructor, but not defining it, i.e. you're telling the compiler that it's in some other compilation unit. The compiler won't complain, but the linker will. If you replace: private this(); with: private this() {} it should work. A. On 1/24/19 1:48 PM, JN

Re: How to disable/hide constructor when using factory method?

2019-01-24 Thread JN via Digitalmars-d-learn
On Wednesday, 23 January 2019 at 19:41:44 UTC, Alex wrote: On Wednesday, 23 January 2019 at 19:26:37 UTC, JN wrote: class Foo { static Foo makeFoo() { Foo f = new Foo(); return f; } } void main() { Foo f = Foo.makeFoo(); } For a code like this. I'd like all

Re: How to disable/hide constructor when using factory method?

2019-01-23 Thread Alex via Digitalmars-d-learn
On Wednesday, 23 January 2019 at 19:26:37 UTC, JN wrote: class Foo { static Foo makeFoo() { Foo f = new Foo(); return f; } } void main() { Foo f = Foo.makeFoo(); } For a code like this. I'd like all users of the class to be forced to create instances using the

How to disable/hide constructor when using factory method?

2019-01-23 Thread JN via Digitalmars-d-learn
class Foo { static Foo makeFoo() { Foo f = new Foo(); return f; } } void main() { Foo f = Foo.makeFoo(); } For a code like this. I'd like all users of the class to be forced to create instances using the static method makeFoo. I want to disallow "new Foo()".