Re: virtual destructor in C++ integration: bug or me being stupid?

2015-12-30 Thread Atila Neves via Digitalmars-d-learn

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:

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();
}


Ugh. As long as it works... thanks!

Atila


virtual destructor in C++ integration: bug or me being stupid?

2015-12-29 Thread Atila Neves via Digitalmars-d-learn

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


Re: virtual destructor in C++ integration: bug or me being stupid?

2015-12-29 Thread Adam D. Ruppe via Digitalmars-d-learn

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();
}