Beta D 2.069.0-b1
Rainer Schuetze via Digitalmars-d-announce
digitalmars-d-announce at puremagic.com
Wed Oct 14 09:59:37 PDT 2015
On 14.10.2015 15:26, Szymon Gatner wrote:
>>
>> To get compatible class layout, the D compiler has to omit it's class
>> info entry in the vtable of C++ classes. In addition D doesn't know
>> about C++ RTTI (I don't know if this is planned to add), so it cannot
>> do the dynamic cast from Operation to Subtract.
>>
>> I have not tried, but calling the virtual destructor instead of
>> destroy() might just work?
>
> Mint that this code comes from Adam Ruppe's book, and it is suppose to
> be working code. Also mind that Subtract is D class and instantiated on
> D side, it is only briefly passed to C++ for usage.
Check the disassembly: the compiler is not even trying to do a
conversion, it just loads null. There is no usable type information in a
C++ interface.
If you know the object "animal" is of type Subtract, you can get the
object pointer by manually subtracting the pointer difference from the
passed pointer:
auto ptr = cast(void*)animal;
ptr -= cast(void*)cast(Operation)cast(Subtract)ptr - ptr;
auto cat = cast(Subtract) ptr;
More information about the Digitalmars-d-announce
mailing list