<p dir="ltr">On 27 Jan 2016 7:10 am, "Elie Morisse via Digitalmars-d" <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br>
><br>
> On Tuesday, 26 January 2016 at 15:53:39 UTC, Manu wrote:<br>
>><br>
>> So, you're saying that if you have an 'I' pointer, which may be implemented by a C++ class, it still needs to be able to cast to Object, and therefore fails? I wonder if a C++ class could somehow be promoted to a D class when being derived in D, by having an Object placed somewhere.<br>
><br>
><br>
> It helps that Object is a just a handful of virtual methods.<br>
><br>
><br>
> On Tuesday, 26 January 2016 at 16:25:35 UTC, Benjamin Thaut wrote:<br>
>><br>
>> For a D class the first entry in the vtable is the classinfo. Thus the problem if you derive a D class from a extern(C++) base class. I don't see any way to actually fix this, adjusting the this pointer won't help. Once you derive a D class from a extern(C++) base class it is no longer a fully functional D class. For example monitor (e.g. synchronized methods) won't work.<br>
><br>
><br>
> Calypso has "hybrid" D classes inheriting from C++, with this layout:<br>
><br>
> - D vptr<br>
> - D monitor<br>
> { start of C++ class }<br>
> - C++ vptr<br>
> - C++ fields...<br>
> - might be other vptr and fields if the C++ class has more than one base<br>
> { end of C++ class }<br>
> - D fields...<br>
><br>
> and when downcasted to the C++ base class the "this" pointer gets adjusted to point towards the start of the C++ class.</p>
<p dir="ltr">This is exactly what I had in mind.<br>
An alternative would be to place Object at the start of 'D fields', same fixup logic.</p>