Can we just have struct inheritence already?

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Sat Jun 22 06:29:43 UTC 2019


On Friday, 21 June 2019 at 22:19:12 UTC, bioinfornatics wrote:
> struct Employee{
>   delegate: get_age, to: _person
>   delegate: get_experience, to: _career
>
>   immutable Person _person;
>   immutable Career _career;

Listing all methods isn't very helpful, if that is the 
suggestion. Then a more consistent syntax would be

struct Employee {
alias getage = _person.getage;
alias get_experience = _career.get_experience;


Yet, that does not solve the MI problems.  Some are:

1. What to do if you both superclasses has a length() method.

2. What do do if both superclasses has used the same method name 
for unrelated concepts?

If there is no overlap semantically then problem 1 and 2 can be 
resolved with a cast to the super class, so that you get the 
right method.

However, what if the subclass has to modify them to retain the 
correct semantics? Which is really what MI problems are about.

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
}


Ola.




More information about the Digitalmars-d mailing list