digitalmars.D.learn - virtual destructor in C++ integration: bug or me being stupid?
- Atila Neves (30/30) Dec 29 2015 cpp.cpp:
- Adam D. Ruppe (8/9) Dec 29 2015 The one I used (well, last time I tried this) was to just put a
- Atila Neves (3/12) Dec 30 2015 Ugh. As long as it works... thanks!
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
Dec 29 2015
On Tuesday, 29 December 2015 at 18:32:23 UTC, Atila Neves wrote:The problem here is that I don't know what the workaround is.The one I used (well, last time I tried this) was to just put a dummy function in the D interface that is a placeholder for it. interface C++Class { // at the same place as void _dontCallMeIamjustadestructor(); void other_function_you_actually_want(); }
Dec 29 2015
On Tuesday, 29 December 2015 at 18:41:41 UTC, Adam D. Ruppe wrote:On Tuesday, 29 December 2015 at 18:32:23 UTC, Atila Neves wrote:Ugh. As long as it works... thanks! AtilaThe problem here is that I don't know what the workaround is.The one I used (well, last time I tried this) was to just put a dummy function in the D interface that is a placeholder for it. interface C++Class { // at the same place as void _dontCallMeIamjustadestructor(); void other_function_you_actually_want(); }
Dec 30 2015