standard alias for a class name inside the class code?
dan via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat May 28 17:48:20 PDT 2016
On Sunday, 29 May 2016 at 00:28:13 UTC, Mithun Hunsur wrote:
> On Sunday, 29 May 2016 at 00:14:17 UTC, dan wrote:
>> Is there a standard alias for a class name inside class code?
>>
>> Something like 'this' referring to a class instance, but
>> referring instead to the class itself?
>>
>> [...]
>
> typeof(this) gets you the type of the current class. :)
Great!!
Thanks Mithun!
That certainly works.
But i sure don't understand how.
Especially in a declaration like
static typeof(this) make_instance( )
but also in the 'new typeof(this)'. In both cases, 'this'
doesn't even exist.
In fact, if you make a reference to this inside the static
function make_instance(), you get an error:
'this' is only defined in non-static member functions, not
make_instance
So the compiler itself states that 'this' is not defined.
But nevertheless, your method absolutely does work.
So i suppose i should not look a gift horse in the mouth, but i'm
still puzzled.
Anyhow, thanks a million, because whether or not i understand
your idiom, it is exactly what i need.
dan
More information about the Digitalmars-d-learn
mailing list