Why can't I inherit (extend) structs?

Jarrett Billingsley kb3ctd2 at yahoo.com
Tue Oct 10 20:26:01 PDT 2006


"rm" <roel.mathys at gmail.com> wrote in message 
news:egh0bu$2155$1 at digitaldaemon.com...
> Lionello Lunesu wrote:
>> It's not a big deal, since I can use composition
>
> but mixin' it in, works nicely

Then you have to make sure to mix in the correct base structs in the correct 
order, and you still don't get type polymorphism (i.e. you can't have a 
pointer to a Base struct point to a Derived struct; you have to write Base* 
b = cast(Base*)derived;).

Not to mention the sheer pain in the behind of managing a struct and its 
matching "members" template.  It seems far more intuitive to be able to 
write

-------
struct Base
{
    int x;
}

struct Derived : Base
{
    int y;
}
-------

Than

-------
template BaseMembers()
{
    int x;
}

struct Base
{
    mixin BaseMembers;
}

template DerivedMembers()
{
    int y;
}

struct Derived
{
    mixin BaseMembers;
    mixin DerivedMembers;
}
-------

Technically in this example you don't need to have DerivedMembers, but if 
you wanted to derive from Derived, you'd have to. 





More information about the Digitalmars-d-learn mailing list