Can we just have struct inheritence already?

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Sun Jun 9 11:51:05 UTC 2019


On Sunday, 9 June 2019 at 11:31:46 UTC, Ola Fosheim Grøstad wrote:
> Use private inheritance of base class.

Or add  a feature that make subclass references const so that you 
cannot assign to just the base class, unless the subclass 
explicitly allows it.

Many possibilities for preventing assignment to base class only 
by using static typing.

Of course, it has to be thought through.

A third option is to provide "tagged" struct where a classifier 
function can determine the object type and pick the right 
"virtual" assignment operator (using a switch statement 
internally).

A fourth option is to prevent sub-structs from overriding methods 
in the base struct and forbid assignment to be sub-struct 
dependent.

A fifth option would be to have abstract base structs that cannot 
be instantiated, and make it so it has no default 
methods/operators. I assume this would allow multiple inheritance 
of abstract base structs. You could create new abstract base 
structs that inherits from other abstract base structs that are 
non-referencable outside the abstract base struct (so that you 
can resolve name collisions).




More information about the Digitalmars-d mailing list