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:02:40 PDT 2017
On Saturday, 27 May 2017 at 16:52:17 UTC, Stanislav Blinov wrote:
> But structs in D have none of that.
Neither does C++ if you don't add a virtual function to it, so it
would be the same.
My question isn't whether structs have it now, but if the concept
struct and class could be merged. Basically, the question is: are
there features that are incompatible in terms of semantics?
The class reference type should be fixable with a rewrite into
templated smart pointers, so no need for big changes there, I
think. The "new" construct would have to change a little bit so
that it instantiates the pointed-to-type and not the
reference-type.
> If your "struct _class_SomeThing" would simply describe the
> same memory layout of classes that we have today, then no
> language change is necessary, it's purely a library solution.
> Well... maybe we'd need to add class postblits if we wanted
> copying (which can also be done by hand with a library "clone"
> function and a "special" static __postblit function).
Sure, D tries to stay compatible with C++, so that would dictate
the memory layout.
> If not, then it gets complicated, as in order to retain an
> interface with C++ classes, D would either have to follow C++
> ABI (he-he), or at the very least put the burden of mapping
> member function calls on the programmer.
I thought D matched up to C++ ABI for structs/classes already
(gdc vs g++, ldc vs clang)?
More information about the Digitalmars-d
mailing list