Alias this and inheritance
Aurelien Fredouelle
aurelien.fredouelle+dlang at gmail.com
Sun Nov 5 07:07:43 UTC 2017
The following code does not compile:
struct S { }
class A
{
S s;
alias s this;
}
class B : A
{
}
void main()
{
A asA = new B;
B asB = cast(B)asA;
}
I would expect the last line to successfully cast the B instance
I created back into type B, however this seems to be preempted by
the alias this:
Error: cannot cast expression asA.s of type S to app.B
Is there a way to force this cast to operate on the object of
type A instead of automatically using A.s?
Thanks,
Aurelien
More information about the Digitalmars-d-learn
mailing list