How does inheritance and vtables work wrt. C++ and interop with D? Fns w/ Multiple-inheritance args impossible to bind to?
evilrat
evilrat666 at gmail.com
Tue May 25 18:03:00 UTC 2021
On Tuesday, 25 May 2021 at 17:52:14 UTC, Gavin Ray wrote:
>
> ```d
> void main()
> {
> Derived dlangDerived = new Derived(123);
> printf("[D] Derived.Base1::getSomething() = %d \n",
> dlangDerived.getSomething());
> printf("[D] Derived.Base2::getOtherThing() = %d \n",
> dlangDerived.getOtherThing());
> printf("[D] Derived.Base1::inheritedFunctionWithArgs(5, 10) =
> %d \n",
> dlangDerived.inheritedFunctionWithArgs(5, 10));
> printf("[D] Calling C++ takesADerived() with D Derived* \n");
> takesADerived(dlangDerived);
> }
> ```
> 
That last one with someInt is what I warned about. D ctor messed
up class layout, in this simple case where class data isn't used
it almost works, but will be practically unusable in real
scenarios.
More information about the Digitalmars-d-learn
mailing list