Slow performance compared to C++, ideas?

Jonathan M Davis jmdavisProg at gmx.com
Mon Jun 3 22:58:45 PDT 2013


On Tuesday, June 04, 2013 07:41:11 Rob T wrote:
> Manu, I'm wondering that perhaps you should not be using classes
> at all. You can still create a similar overridable scheme for
> struct methods, and although it may not be as convenient, it will
> work. However a big failure point with stucts is the lack of
> inheritance.
> 
> Structs would IMO be far more useful if they had inheritance.
> Inheritence can be fully removed from the rest of polymorphism,
> so there's no reason why structs which are not polymorphic cannot
> inherit.
> 
> Actually I'd like to know why structs cannot inherit? I hate it
> when I end up creating classes when I have no other reason to
> create a class other than for the ability to inherit.

How would it even work for a struct to inherit without polymorphism? The whole 
point of inheritance is to make it so that you can create types that can be 
used in place of another, and that won't work without references or pointers 
and polymorphism.

Use composition, and if you want to be able to call members of the inner 
struct on the outer struct as if they were members of the outer struct, then 
use alias this or opDispatch to forward them to the inner struct.

- Jonathan M Davis


More information about the Digitalmars-d mailing list