Struct default constructor - need some kind of solution for C++ interop

Ethan Watson via Digitalmars-d digitalmars-d at puremagic.com
Wed Sep 7 04:16:20 PDT 2016


On Tuesday, 6 September 2016 at 14:49:20 UTC, Ethan Watson wrote:
> this( void* pArg = null );

Also doesn't work: this( Args... )( Args args ) if( Args.length 
== 0 )

Just for funsies I tried making my Mutex a class for the purpose 
of embedding it manually in a struct. But thanks to all classes 
inheriting from Object there's 16 bytes at the front of the class 
that I don't want (64-bit build, it's 8 bytes in 32-bit builds 
but we're never going back to 32-bit). So that's very definitely 
out of the question.

static opCall() seems to be the only way to do this then. I can 
autogenerate it for any C++ bound class. But it's inadequate. It 
leaves room for user error when instantiating any C++ object in 
D. It's also another thing that C++ programmers need to be 
thoroughly educated about as Type() in C++11 calls the zero 
initializer, but in D it's effectively the opposite semantics.


More information about the Digitalmars-d mailing list