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

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Mon Dec 13 12:16:03 UTC 2021


On Monday, 13 December 2021 at 12:08:30 UTC, evilrat wrote:
> Yeah but it sucks to have making C++ wrapper just for this. I 
> think either pragma mangle to hammer it in place or helper 
> dummy struct with class layout that mimics this shim logic is a 
> better solution in such cases.
> Literally anything but building C++ code twice for a project.

Does something like this work?


```
class _A {}
struct A {}

extern(C++) void CppFunc(ref const(A) arg);

void func(_A a){
     CppFunc(*cast(A*)a);
}
```


More information about the Digitalmars-d-learn mailing list