Interfacing with basic C++ class

Riccardo M asd at asd.asd
Sun Oct 2 07:48:01 UTC 2022


On Friday, 30 September 2022 at 22:56:06 UTC, Ogi wrote:
> On Thursday, 29 September 2022 at 12:49:06 UTC, Riccardo M 
> wrote:
> When interfacing to C++, disregard the keyword and look at the 
> implementation instead. If all its member functions are 
> non-virtual, map it to struct. Otherwise map it to class. If it 
> defines at least one pure virtual member function, map it to 
> abstract class. If all its member functions are either pure 
> virtual or non-virtual and it contains no fields, map it to 
> interface. Sounds complicated? Well, that’s because C++ is 
> complicated.

Ok, in layman terms, is it correct to say that I should match the 
underlining structure of the object (e.g in terms of vtbl) so 
that C++ side and D side can work with each other correctly?

> In C++, member functions defined inside its class are called 
> *inline* member functions. In contrast to normal functions 
> which must be defined once and only once in your program, 
> inline functions must be defined in every translation unit that 
> uses them. Let’s replicate your linking error in C++:

Well, I didn't know the implications of inlining member 
functions: basically when a member function is inlined, it has no 
linkage so I am pretty much done with using D in such case. While 
in C++ you can import the header and call the member function 
anyway.
The only solution would be reimplementing the offending function 
on D side.


More information about the Digitalmars-d-learn mailing list