www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: object oriented value type

reply Tristam MacDonald <swiftcoder gmail.com> writes:
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.


Jun 30 2007
next sibling parent Johan Granberg <lijat.meREM OVEgmail.com> writes:
Tristam MacDonald wrote:

 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...

I totally agree and hope that this gets added.
Jun 30 2007
prev sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Tristam MacDonald" <swiftcoder gmail.com> wrote in message 
news:f666iv$2r1m$1 digitalmars.com...
 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...

The current behavior of opAssign not what you need? Ctors/dtors for structs are supposedly coming, but who knows when..
Jun 30 2007