hi, im trying to interface a cpp class. I'd like to interface a bigger library and I'm trying to figure out the minimum effort.

--- c++ part:
#include <iostream>
class some_class {
public:
  static some_class* __ctor();
  some_class();
  ~some_class();
  void some_method();
};
some_class* some_class::__ctor() {
  auto thiz = new some_class();
  std::cout << "hello from __ctor, thiz:" << thiz << std::endl;
  return thiz;
}
some_class::some_class() { std::cout << "some_class constructor, this:" << this << std::endl; } some_class::~some_class() { std::cout << "some_class destructor, this:" << this << std::endl; }
void some_class::some_method() {
std::cout << "some_class some_method, this:" << this << std::endl;
}

--- d part:
extern (C++) {
  class some_class {
    final this();
    final ~this();
    final void some_method();
  }
}
void main() {
some_class someClass = new some_class(); // works, __ctor() gets called, and it calls the constructor.
  someClass.some_method; // works
destroy(someClass); // crashes (SIGSEGV) inside lifetime.d rt_finalize2()
}

---
OS: ubuntu 17.10
compiler: DMD64 D Compiler v2.077.0

I could do the instancing/destruction by functions and write a custom d class that calls these methods in this()/~this(). But I was hoping not needing to write a class in D AND in cpp. and i was hoping to save another step/level of instancing.

Any idea how to make the destructor of cpp compatible with "~this()"?

Thx in advance
Markus

Reply via email to