Can we just have struct inheritence already?
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Sat Jun 22 06:49:20 UTC 2019
On Saturday, 22 June 2019 at 06:29:43 UTC, Ola Fosheim Grøstad
wrote:
> Then you need som way of overloading a function that calls a
> specific attribute of a struct. So you need overloading on
> attributes, not only overloading on types, yet you also need a
> reference to the parent struct.
>
> So you need to be able to do something like
>
> int length(SubStruct.attributename* this) {
> this.parent
> }
In other words, you need static virtual methods. Perhaps a better
syntax would be something along the lines of:
struct SubClass {
int _length;
inherit SuperClass1 {
int length(){ this.super.length() + this.parent._length}
} attribute1;
inherit SuperClass2 {
int length(){ this.super.length() - this.parent._length}
} attribute2;
}
It is difficult to find a syntax that isn't confusing. Probably
better to do it with interfaces.
More information about the Digitalmars-d
mailing list