March 14, 2019 Re: local class instance (at module-level) | ||||
---|---|---|---|---|
| ||||
On Thu, Mar 14, 2019 at 12:05:22PM +0100, spir via Digitalmars-d-learn wrote: > I desperately try to declare/define/initialise a simple class instance at module-level. This is a special (conceptually static and immutable) instance used as a "marker", that just should exist and be accessible by methods of this class and/or other classes defined in the same module. (Thus I don't care if TLS.) I use it as a remplacement for null, to avoid semantic confusion and unhelpful segfaults in case of bug. Does this work? class C { ... } immutable C c0; static this() { c0 = new C(...); } T -- To err is human; to forgive is not our policy. -- Samuel Adler |
March 14, 2019 Re: local class instance (at module-level) | ||||
---|---|---|---|---|
| ||||
On 14/03/2019 12:16, H. S. Teoh via Digitalmars-d-learn wrote:
> On Thu, Mar 14, 2019 at 12:05:22PM +0100, spir via Digitalmars-d-learn wrote:
>> I desperately try to declare/define/initialise a simple class instance
>> at module-level. This is a special (conceptually static and immutable)
>> instance used as a "marker", that just should exist and be accessible
>> by methods of this class and/or other classes defined in the same
>> module. (Thus I don't care if TLS.) I use it as a remplacement for
>> null, to avoid semantic confusion and unhelpful segfaults in case of
>> bug.
>
> Does this work?
>
> class C { ... }
> immutable C c0;
> static this() {
> c0 = new C(...);
> }
>
>
> T
Oh yes, that was it ! Thank you very much.
diniz
|
Copyright © 1999-2021 by the D Language Foundation