Singletons, alias this and DMD crashing
Jacob Carlborg
doob at me.com
Fri May 10 02:50:52 PDT 2013
On 2013-05-09 15:07, Leandro Motta Barros wrote:
> Thanks for the comment! I noticed this wouldn't compile, though I
> haven't really wondered why so. My email was more about the compiler
> bug than about using alias this with singletons.
>
> Anyway, while trying to circumvent the compiler bug, I did this:
>
> import std.stdio;
>
> class SImpl
> {
> void foo()
> {
> writeln("foo!");
> }
>
> private this() { }
> }
>
> class S
> {
> static @property SImpl instance()
> {
> if (_i is null)
> _i = new SImpl();
>
> return _i;
> }
>
> static SImpl _i;
>
> alias instance this;
> }
>
> void main()
> {
> S.foo();
> }
>
> This works and compiles with DMD 2.062. (I don't like to have
> to write this additional code manually, but I'll try to make something
> about it :-) )
Aha, you added an additional class.
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list