Define "createXXX" functions for the constructors of class XXX
Johan Engelen via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jan 23 11:42:29 PST 2016
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(...); }".
I am sure there must be some great way to automatically generate
these creator functions, but I don't know how to do it.
In the C++-header I will write manually:
XXX* createXXX(int a, int b);
XXX* createXXX(bool flag);
In D source:
extern (C++) class XXX {
this(int a, int b) { /+...+/ }
this(bool flag) { /+...+/ }
}
// Somehow define these guys automatically,
"genCreateCtors!(XXX)" ?
XXX createXXX(int a, int b) { return new XXX(a, b); }
XXX createXXX(bool flag) { return new XXX(flag); }
Thanks a lot!
Johan
More information about the Digitalmars-d-learn
mailing list