On Saturday, 23 January 2016 at 19:42:29 UTC, Johan Engelen wrote:
Hi all,
While trying to interface C++ and D, I have to new a few D objects in C++ code. I am doing this using a D function: "XXX createXXX(...) { return new XXX(...); }".

An easier way for trivial constructors (note parents!), is to also define the constructor inline in C++ header.

in .d:
  extern (C++) class Klass {
    int b;
    this(int a) { b = a+1; }
  }
in .h:
  class Klass {
    int b;
    Klass(int a) { b = a+1; }
  };

It's what DDMD does in a few cases.

Reply via email to