Singletons, alias this and DMD crashing
Jacob Carlborg
doob at me.com
Thu May 9 03:04:11 PDT 2013
On 2013-05-09 11:48, Jacob Carlborg wrote:
> This won't work. You need to be able to overload on static, which you
> can't. I've tried this with opDispatch.
To elaborate. Below is your original with the "foo" method added.
class S
{
static @property S instance()
{
if (_i is null) // #1
_i = new S();
return _i;
}
static S _i;
alias instance this; // #2
void foo () {}
}
If you try to call it like this: S.foo(), the compiler will complain
that "foo" need access to "this". The "alias this" won't kick in.
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list