A question about C++ interop
YD
diyu60607 at yahoo.com
Fri Mar 27 19:17:05 UTC 2020
Hi, I have a C++ header file which looks like
class A {
public:
static A *create();
virtual int f() const = 0;
};
And there is a C++ library file which provides the
implementation, so that if I write a C++ program and call
auto *p = A::create();
std::cout << p->f() << '\n';
It will work.
Now I want to interface to this C++ library through D, and I wrote
module test;
import std.stdio;
extern(C++) {
class A {
static A *create();
abstract int f() const;
}
}
void main() {
auto p = A.create();
writeln(p.f());
}
This program will compile and link, but it core dumps at the call
to f().
If I wrap up the C++ interface into a C interface (using a void
*), and interface to the wrapped-up C library through D, it will
work fine.
So what am I doing wrong here? Thanks!
More information about the Digitalmars-d-learn
mailing list