Why can't I inherit (extend) structs?

Bill Baxter dnewsgroup at billbaxter.com
Sun Oct 15 17:20:42 PDT 2006


Georg Wrede wrote:
> 
> This could of course be implemented in D. And I think it would be useful.
> 
> struct A
> {
>     somefield a;
> }
> 
> struct B: A
> {
>     otherfield b;
> }
> 
> And the compiler would simply slap the A fields at the beginning of B. 
> Off-hand I don't see why this would be difficult to implement. But 
> implementing this would cause demands for multiple inheritance.
> 
> struct A
> {
>     alpha a;
> }
> struct B
> {
>     beta b;
> }
> struct C: A B
> {
>     gamma c;
> }
> 
> And all's well, except when folks start doing
> 
> struct D: B A
> {
> }
> struct E: C D
> {
> }
> 
The response to "demands for multiple inheritance" should simply be "No".

D doesn't support multiple inheritance for classes even, so it seems odd 
that it would go out of its way to allow it for structs.  I see nothing 
wrong with just saying structs can only do single inheritance.

--bb



More information about the Digitalmars-d-learn mailing list