standard alias for a class name inside the class code?

dan via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat May 28 21:22:14 PDT 2016


On Sunday, 29 May 2016 at 02:44:33 UTC, jhps wrote:
> On Sunday, 29 May 2016 at 00:48:20 UTC, dan wrote:
>> 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.
>
>
> https://dlang.org/spec/declaration.html#Typeof
>
> it's another 'this' that has not the same semantic as the 
> reference holder.
> Just like 'const' can have 3 meanings, 'this' also:
>
> - this.member: typical usage, it hold the instance reference
> - void foo(this T)(): template this parameter, T is 
> typeof(this) where the template is used.
> - typeof(this): you can use it in static func, this 'this' is 
> not the 'this' instance.

OK, thanks JHPS for the detailed explanation of this construction 
Mithun pointed out, and also for the link.  It makes a lot of 
sense the way you put it.



More information about the Digitalmars-d-learn mailing list