On Wednesday, 23 May 2018 at 07:09:40 UTC, Manu wrote:
C++:
---------------------------------------
class C {};
template <typename T>
void create(T** x);
---------------------------------------
D:
---------------------------------------
extern(C++) class C {}
void create(T)(T* x);
---------------------------------------
Trouble is; in CPP, the template mangles as a C, but in D, the
class mangles as C*... so the mangling doesn't match.
`template<typename Class>` is an unbelievably common occurrence
in C++... but how do we express a signature that mangles
correctly in D? D always mangles `Class` as `Class*`... which
changes the signature.
_<
I believe you are looking for
extern(C++,class) struct C {}
void create(T)(T** x);
or
extern(C++,struct) class C {}
void create(T)(T** x);
I can't remember which is the one you want here (still half
asleep from jet lag).
in the case of e.g. extern(C++,struct) class C {}
this tells the D compiler that is should mangle it as though it
is a struct (as it is declared in C++ as a struct) but it
actually has a vtable and behaves like a class from the D school
of thought. Vice versa for extern(C++,class) struct C {}