Can we just have struct inheritence already?

XavierAP n3minis-git at yahoo.es
Sat Jun 22 07:10:26 UTC 2019


If we want multiple inheritance or even virtual methods in 
structs, completely new and severe problems appear. And I don't 
think these patterns have utility that justifies these problems 
or even their existence alone.

Single struct inheritance with no virtual methods presents in my 
opinion no problems, and it would be in many cases a better, more 
concise, boilerplate-less, clearer, cleaner way to accomplish the 
type extension and not repeating oneself that currently we can do 
only by composition and explicit forwarding, alias this, or 
macro-ish template mixins.

On Saturday, 22 June 2019 at 06:29:43 UTC, Ola Fosheim Grøstad 
wrote:
> 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;

Explicit forwarding is already/always possible. These syntaxes 
are not so more concise than

auto getAge() { return _person.getAge(); }

So I'd see no point in burdening D with adding such candy 
features.


More information about the Digitalmars-d mailing list