On Tuesday, 8 August 2017 at 21:04:23 UTC, Jacob Carlborg wrote:
On 2017-08-08 20:51, Johan Engelen wrote:
Hi all,
Currently, it is not possible to call the C++ function "void
foo(Klass&)" when Klass is an extern(C++) _class_ on the D
side. You
have to declare Klass as a D _struct_, otherwise there is no
way to get
the correct mangling. When Klass has virtual functions, you're
hosed.
For more context (involving "const"), see:
https://forum.dlang.org/post/[email protected]
Is this problem on anybody's radar?
What are the ideas to resolve this issue, or are we content
never to
solve it?
One way to do it, that might be a bit confusing, is to force
the declaration of the function to explicitly specify a pointer
or a reference. Currently it looks like it's an implicit
pointer.
extern (C++) class Klass {}
void foo(Klass*); // ok
void foo(ref Klass); // ok
void foo(Klass); // error
Of course, there's always pragma(mangle) as well.
sorry for hijacking the thread but i have a similar question:
i was wondering if i could write a wrapper for a C++11 library
called cpr. in one of its header files
(https://github.com/whoshuu/cpr/blob/master/include/cpr/auth.h#L13) it has a generic constructor that initializes its member fields. i had no idea as to how to do it. then i came up with the following line:
extern (C++, cpr) {
this(UT, PT)(ref UT username, ref PT password) { ... }
}
when i compiled it with the .a lib given, it worked. do you guys
think i did it right? the &
my second question is: i have no idea what's going on in this
file:
https://github.com/whoshuu/cpr/blob/master/include/cpr/body.h i'd
appreciate some pointers.