Derived type
novice2
sorryno at em.ail
Thu Apr 1 19:44:14 UTC 2021
thanks, i tried 2 variants:
```d
struct Tnew {TBase payload; alias payload this;}
```
```d
enum Tnew : Tbase {init = Tbase.init}
```
both works, but 1-st not allow "2 level" cast:
```d
struct Xptr {void* payload; alias payload this;} //Xptr based on
void*
struct Xobj {Xptr payload; alias payload this;} //Xobj based on
Xptr
Xptr xptr = cast(Xptr) null; //OK
Xobj xobj = cast(Xobj) null; //ERROR
Xobj xobj = cast(Xobj) cast(Xptr) null; //OK, needs both levels
explitity
```
```d
enum Xptr : void* {init = (void*).init} //Xptr based on void*
enum Xobj : Xptr {init = Xptr.init} //Xobj based on Xptr
Xptr xptr = cast(Xptr) null; //OK
Xobj xobj = cast(Xobj) null; //OK
```
so "enum" variant is better for me, thanks!
More information about the Digitalmars-d-learn
mailing list