How to pass a class by (const) reference to C++

Tim tim.dlang at t-online.de
Mon Dec 13 21:28:44 UTC 2021


On Monday, 13 December 2021 at 21:17:49 UTC, Jan wrote:
> Unfortunately no. Maybe the cast would even make it work, but I 
> can't have "A" and "_A" in D as separate types, because the 
> class is supposed to link to C++ functions and thus renaming it 
> from A to _A breaks that. On the other hand I can't give the 
> struct another name either, because that's how it is linked to 
> in "CppFunc".

The easiest workaround is probably to set the mangling manually:

pragma(mangle, "_Z7CppFuncRK1A")
extern(C++) void CppFunc(const A arg);

This mangling is for the Itanium ABI, which is used by Linux and 
other operating systems. It needs to be different for Windows.


More information about the Digitalmars-d-learn mailing list