On Thursday, 19 September 2024 at 15:56:06 UTC, Richard (Rikki) Andrew Cattermole wrote:
>…
Would be nice to have proper struct inheritance but there are a lot of things we have to consider.
What about slicing?
struct A {
int x;
}
struct B : A {
int y;
this(int x, int y) {
super(x);
this.y = y;
}
}
void main() {
B b1 = B(1, 2), b2 = B(3, 4);
A* p = &b2;
*p = b1;
writeln(b2); // B(1, 4)
}
If we want something better than alias this
, we have to prohibit implicit partial assignment via pointer/reference. When it’s necessary, it would still be possible with *p = cast(A)b1;
.