Why can't structs be derived from?

Daniel Gibson metalcaedes at gmail.com
Tue Mar 15 13:38:44 PDT 2011


Am 15.03.2011 21:29, schrieb Jens:
> Daniel Gibson wrote:
>> Am 15.03.2011 21:07, schrieb Jens:
>>> How is it different in D where all polymorphic objects are reference
>>> types? Take have the design space away, make everything a glorified
>>> pointer and things are better?
>>
>> They obviously are. Successful languages like Java and C# do it. It's
>> less error-prone and you don't have to worry about dereferencing
>> stuff all the time (sometimes even multiple dereferences at once,
>> like in my example).
> 
> More toward Java-class-language then than C++-level language. Sacrificing 
> stack objects was like throwing out sharp knives from the kitchen. I 
> understand.
> 

If you want value types use structs. Maybe with alias this or mixins to "extend"
them.
Or use emplace (see http://www.digitalmars.com/d/2.0/phobos/std_conv.html ) with
classes if you wanna play with sharp tools.
It's not like you can't (risk to) cut yourself with D, it's just easier not to.


More information about the Digitalmars-d mailing list