using C++ classes from D

Martin Nowak dawg at dawgfoto.de
Thu Nov 24 23:22:34 PST 2011


After going astray while doing C++ class bindings using smart_ptrs and ugly
mixins I think I found a really neat way.
It consists of a C++ header that defines a d_new template function.
It will allocate it's types from the D GC while hooking the C++ type's
destructor to a D finalizer. It even allows for nested scanning of C++
classes and allocating other data, e.g. arrays.

To use C++ class from D one only needs to define one factory function and
add the class declaration to a D source file and link in the d_new module.

Currently uses boost and offers no constructor arguments, due to the  
dreaded
forwarding problem.

https://gist.github.com/1391734

martin


More information about the Digitalmars-d mailing list