object oriented value type

Robert Fraser fraserofthenight at gmail.com
Mon Jun 25 11:36:11 PDT 2007


What's the point? There's no way to refer to a subtype by the supertype (since the compiler wouldn't know what size the struct would be), so the only OO feature you'd get is mere aggregation, which should be explicit anyway.

You can have private struct functions/members - all the privacy concerns are at the module level, so a private struct member is module-private, just as a private class member is.

I do think having a syntax to add properties to primitive types is a good idea, though, in the same way as the funky array syntax works now.

Ender KaShae Wrote:

> I find it a little disappointing that D does not have any support for the C++ way of object oriented value types, both c# and D have structs that pass by value but do not support inheritance and classes passed by reference that do support inheritance, D adds injury to insult by prohibiting hidden members in structs.  But what about when you need a type that passes by value and supports inheritance, I don't think that the structs necessarily need to be changed, rathe I think that a new type should be created as a combination of a struct and a class.  This would be particularly useful in inheriting from primitave types.  Another example is having a mixedFraction inherit from fraction.




More information about the Digitalmars-d mailing list