cast problem about alias this

Sobaya sobaya007 at gmail.com
Mon Jan 29 19:40:43 UTC 2018


class Parent {
     int x;
     alias x this;
}

class Child : Parent {
}

void main() {
     Parent p = new Child;
     Child c = cast(Child)p; // cannot cast `int` to `Child`
}

In this code, I got a compile error.
How can I cast p to Child?


More information about the Digitalmars-d-learn mailing list