cpp.cpp:

class Oops {
public:

    virtual ~Oops() {}
    virtual int number() const { return 42; }
};

Oops* newOops() {
    return new Oops;
}

d.d:

import std.stdio;


extern(C++) {
    interface Oops {
        int number() const;
    }
    Oops newOops();
}

void main() {
    auto oops = newOops();
    writeln(oops.number());
}


I get garbage in the output (I found this due to a crash in much more complicated code). If I comment out the virtual destructor, it works.

It seems that the presence of the virtual destructor changes the layout and D doesn't know about it. Thinking about it now, it makes sense, how would D know?

The problem here is that I don't know what the workaround is. Abstract classes in C++ usually have virtual destructors...

Atila

Reply via email to