Singleton Pattern with struct

ParticlePeter ParticlePeter at gmx.de
Thu Jan 24 07:06:32 PST 2013


> Even if Singleton.instance returns by ref, s object is still 
> stack-allocated struct, which is not affected by further 
> modification of private pointer.

But where and when is ( a second  ? ) Singleton created or 
duplicated ? The only ctor is in the static instance ( it is 
called only once according to my debugger ) and allocates a 
Singleton instance on the Heap ( as far as I understand "new 
Struct" ). The return statement does return a reference ( to a 
pointer, even that shouldn't be necessary ) so I would expect ... 
well a reference and not a copy. So where does the second object 
come from ?


More information about the Digitalmars-d-learn mailing list