Classes or stucts :: Newbie

spir denis.spir at gmail.com
Mon Dec 20 01:52:58 PST 2010


On Mon, 20 Dec 2010 01:29:13 -0800
Jonathan M Davis <jmdavisProg at gmx.com> wrote:

> > For me, the important difference is that classes are referenced, while
> > structs are plain values. This is a semantic distinction of highest
> > importance. I would like structs to be subtype-able and to implement
> > (runtime-type-based) polymorphism.  
> 
> Except that contradicts the facts that they're value types. You can't have a 
> type which has polymorphism and is a value type. By its very nature, 
> polymorphism requires you to deal with a reference.

Can you expand on this?

At least Oberon has value structs ("records") with inheritance and polyporphism; I guess the turbo Pascal OO model was of that kind, too (unsure) -- at least the version implemented in freepascal seems to work fine that way. And probably loads of less known PLs provide such a feature.
D structs could as well IIUC: I do not see the relation with instances beeing implicitely referenced. (Except that they must be passed by ref to "member functions" they are the receiver of, but this is true for any kind of OO, including present D structs.)

(I guess we have very different notions of "reference", as shown by previous threads.)


Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com



More information about the Digitalmars-d-learn mailing list