Structure's inheritance

Maxim Fomin maxim at maxim-fomin.ru
Sun May 12 04:56:50 PDT 2013


On Sunday, 12 May 2013 at 11:21:16 UTC, Temtaime wrote:
> Hello to all !
> I'm surprised that there is no structure's inheritance.

This was done by Walter Bright deliberately because he believes
that polymorphism does not play well with automaic lifetime.

> There is a problem:
> I want to make Matrix MxN class. I also want to make child 
> classes Square Matrix and Vector from it with additional 
> functions.
> I don't want use "class" cause of "new" overhead. Std 
> typecons's Scoped - workaround with many restrictions, so it 
> isn't true solution.
>
> I'm tried mixin template but there is no luck. I don't know how 
> to declare multiplication operator for example.
>
> Any suggestions ?
> Regards.

You can place base struct instance inside nested and use alias
this. Note that currently multiple alias this are not supported.
Also note that you cannot override functions because there are no
virtual table for structs.


More information about the Digitalmars-d-learn mailing list