Why can't I inherit (extend) structs?

Lionello Lunesu lio at lunesu.remove.com
Mon Oct 16 22:54:13 PDT 2006


Johan Granberg wrote:
> Derek Parnell wrote:
>> And I'd go so far as to say that the term 'inheritance' is a bit strong.
>> Maybe just 'derivation' as we would be deriving a new struct definition
>> from existing definitions, but there is no implied linkage between 
>> them at
>> runtime. 
> 
> If it is just derived from that is wanted wouldn't it bee easier with a 
> syntax like this.
> 
> struct foo
> {
>     int b;
>     int c;
> }
> struct bar
> {
>     int a
>     include foo;
>     int d
> }
> 
> the struct bar would now have four fields (a,b,c,d)
> 
> this way their is no way to misunderstand it for inheritance and if one 
> want a foo* one can always take the addres of the first element.

Good! Perhaps the keyword "mixin" could be (mis)used for this?

L.



More information about the Digitalmars-d-learn mailing list