Singleton Pattern with struct
Maxim Fomin
maxim at maxim-fomin.ru
Thu Jan 24 07:19:13 PST 2013
On Thursday, 24 January 2013 at 15:05:15 UTC, Jacob Carlborg
wrote:
> On 2013-01-24 15:43, Maxim Fomin wrote:
>
>> Even if Singleton.instance returns by ref, s object is still
>> stack-allocated struct, which is not affected by further
>> modification of
>> private pointer.
>
> The struct is allocated using "new".
This is about "auto s = " in main, not about "new" in method.
Type of s is Singleton, not Singleton* or "ref Singleton".
Singleton s = Singleton.instance; // is compiled when
Singleton* s = Singleton.instance; // is not - Error: cannot
implicitly convert // expression (instance()) of type Singleton
to Singleton*
More information about the Digitalmars-d-learn
mailing list