www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: object oriented value type

reply Ender KaShae <astrothayne gmail.com> writes:
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.

Then how does c++ do it?
 Ender KaShae Wrote:
 
   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,
rather 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 29 2007
parent Robert Fraser <fraserofthenight gmail.com> writes:
Ender KaShae Wrote:

 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.

Then how does c++ do it?

C++ slices off subclass fields if assigned to a superclass type. If class Foo has a field x and class Bar, which extends Foo, has a field y, then: Foo f = Bar(); will only store the value of x, not y.
Jun 29 2007