virtual destructor in C++ integration: bug or me being stupid?
Atila Neves via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Dec 29 10:32:23 PST 2015
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
More information about the Digitalmars-d-learn
mailing list