What would break if class was merged with struct

Ola Fosheim Grøstad via Digitalmars-d digitalmars-d at puremagic.com
Sat May 27 10:30:49 PDT 2017


On Saturday, 27 May 2017 at 17:22:02 UTC, Stanislav Blinov wrote:
> But they are incompatible precisely because structs "don't have 
> it". Inheritance for one. Reference semantics for another. A 
> class reference is a pointer in disguise, struct is full layout 
> on the stack. The only way to retain inheritance and reference 
> semantics while removing "class" keyword would be not to merge 
> classes into structs, but structs into classes. And then what, 
> always allocate on the heap?

I don't understand this argument, why would this be more 
difficult for D than C++?

You lower class into struct (with virtual, interfaces, whistles 
and bells) and retain reference semantics by making it 
unavailable for D-move-semantics.

> Which is all possible as a library with zero language changes. 
> But for that to work, classes shall remain classes and structs 
> shall remain structs.

Huh?

> If that were true, we wouldn't even need the "extern(C++)", 
> would we?

Sounds more like an implementation detail to me.



More information about the Digitalmars-d mailing list