Singleton in Action?
Ron Tarrant
rontarrant at gmail.com
Mon Feb 4 10:36:49 UTC 2019
On Sunday, 3 February 2019 at 18:53:10 UTC, Jacob Carlborg wrote:
> You don't need to make it so complicated. Here's a simpler
> example:
Excellent. Thank you. Simple is best.
> private __gshared auto instance_ = new DSingleton;
My understanding is that in D, this line effectively says: the
singleton is created at compile time and can't be changed, ever.
Is that a fair assessment?
>
> private this() // private to make sure no one else can
> create an instance
I've seen comments similar to this in several examples. When you
say "no one else" you're personifying callers? And so this means:
No caller outside the object? Which really amounts to: Since no
one INside the object WILL call this() and no one OUTside CAN
call this(), it won't ever get called.
> writeln(DSingleton.instance);
No '()' needed for the call to DSingleton.instance?
If it's called again from somewhere else, say from within an
object function several levels of scope away, it's called the
same way?
More information about the Digitalmars-d-learn
mailing list