Derived type

Mike Parker aldacron at gmail.com
Wed Mar 31 00:27:00 UTC 2021


On Tuesday, 30 March 2021 at 19:33:31 UTC, novice2 wrote:
> On Tuesday, 30 March 2021 at 19:12:29 UTC, Ali Çehreli wrote:
>> "Derived type" is used in the context of object oriented 
>> programming at least in D
>
> Sorry, i use wrong termin.
> I just want create new type Tnew, based on exist type Tbase.
> Tnew have same allowed values, same properties, same allowed 
> operations as Tbase.
> Compiler should distinguish New from Tbase.
> Allowed implicit cast Tnew to Tbase.
> Prohibited implicit cast Tbase to Tnew.
> Allowed exlicit cast Tbase to Tnew.

That's precisely what the alias this feature is intended to do.

https://dlang.org/spec/class.html#alias-this

> Thanks, this is what i want.
> I just think that Typedef do it for me, hide this boilerplait 
> code.

That's not the intended purpose of the Typedef template. Its 
documentation explicitly says it "allows the creation of a unique 
type which is based on an existing type". The keyword there is 
*unique*.


More information about the Digitalmars-d-learn mailing list