How does inheritance and vtables work wrt. C++ and interop with D? Fns w/ Multiple-inheritance args impossible to bind to?

Guillaume Piolat first.last at gmail.com
Mon May 24 18:46:00 UTC 2021


On Monday, 24 May 2021 at 17:39:38 UTC, Gavin Ray wrote:
> On Sunday, 23 May 2021 at 21:08:06 UTC, Ola Fosheim Grostad 
> wrote:
>> On Sunday, 23 May 2021 at 21:02:31 UTC, Gavin Ray wrote:
>>> I don't really know anything at all about compilers or 
>>> low-level code -- but is there any high-level notion of 
>>> "inheritance" after it's been compiled?
>>
>> Yes, in the structure of the vtable, which is why the spec is 
>> so hard to read.
>>
>> If possible stick to single inheritance in C++...
>
> Yeah agreed, multiple inheritance is asking for trouble.
>
> But unfortunately when you're binding to existing libraries you 
> don't have control over the API
>
> Hence why I was asking how to make D structs/classes that have 
> compatible or identical vtables to multiply inherited objects 
> to pass as arguments to `extern (C++)` functions.
>
> Also general explanation of what makes a compiled variable 
> compatible in terms of vtable with what's expected as an 
> argument
>
> I'd be grateful for solid information on this

AFAIK multiple inheritance is described in this book 
https://www.amazon.com/Inside-Object-Model-Stanley-Lippman/dp/0201834545

Multiple inheritance is a rare topic here, I doubt too many 
people know how it works internally.
Java and COM stuck on single-inheritance because it gives you 99% 
bang for the buck, also v-table dispatch in case of multiple 
inheritance is not as straightforward.


More information about the Digitalmars-d-learn mailing list