object oriented value type
Tristam MacDonald
swiftcoder at gmail.com
Sat Jun 30 11:14:55 PDT 2007
Maybe inheritance is not so useful, but constructor/destructor/opAssign for structs would be nice, as lightweight value types with the ability to manage resources are very handy...
Robert Fraser Wrote:
> 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