Are D classes proper reference types?
kinke
noone at nowhere.com
Sat Jun 26 20:03:01 UTC 2021
On Saturday, 26 June 2021 at 13:49:25 UTC, Ola Fosheim Grøstad
wrote:
> Is it possible to inherit from a C++ class and get a D
> subclass, and is it possible to inherit from a D class and get
> a C++ class?
Sure thing, with `extern(C++) class` of course.
> But the best solution is to get to a place where you can hand
> D-objects to other languages with ease without doing a runtime
> conversion from one layout to another.
With C++, you can today, an `extern(C++) class C` is equivalent
to and mangled as C++ `C*`. You can't pass it directly to some
`unique_ptr<C>` or `shared_ptr<T>` of course; an according D
wrapper reflecting the C++ implementation (library-dependent)
would be needed anyway for correct mangling. It'd be implemented
as a templated D struct, similar to how `std::vector` works today
for the MSVC runtime:
https://github.com/dlang/druntime/blob/master/src/core/stdcpp/vector.d
More information about the Digitalmars-d-learn
mailing list