Why can't I inherit (extend) structs?
Lionello Lunesu
lionello at lunesu.remove.com
Tue Oct 10 22:51:50 PDT 2006
"Mike Parker" <aldacron71 at yahoo.com> wrote in message
news:eggji8$1kih$1 at digitaldaemon.com...
> Lionello Lunesu wrote:
>> I like the definition of 'struct' in D: simple aggregations of data. But
>> is there currently a way to extend a struct? Apart from composition, that
>> is. I'd like to do something like this:
>>
>> struct X {
>> int x;
>> }
>> struct Z : X {
>> int z;
>> }
>>
>> Would this feature add complications that I fail to see?
>>
>> It's not a big deal, since I can use composition, but I'll have to name a
>> member for the first struct and repeatedly write it.. And I'm lazy :S
>>
>
> Once you start extending structs, you'll need the same bookkeeping
> overhead required for classes. That eliminates the current distinction
> between them.
I don't need polymorphism and all that, just to add fields to an existing
struct, like Derek's example: struct ColorRGB and then a struct ColorRGBA,
which adds a field for the alpha (=transparency). Seems I can use mixins for
this, at the moment.
But there's shouldn't be extra bookkeeping. It should be like composition;
like adding a nameless instance of the 'base' struct as the first member in
the derived struct.
L.
More information about the Digitalmars-d-learn
mailing list