Using a struct as a wrapper for an extern(C) opaque type, no default constructor, what do?

Jeremy DeHaan via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Dec 16 19:31:37 PST 2015


Hi all. I'm interfacing to some C code which include an opaque 
type and some C functions that create and work with a pointer to 
that type. I want to wrap up everything in a struct, and the only 
thing that seems to bug me is initialization.

Since it is C code, I obviously can't read the function that 
creates the opaque type. Not only that, I can't define a default 
constructor. What are my options here?

This is for an API that is intended to be used by people other 
than myself, so I'd like to use something that doesn't look ugly 
or isn't a hack. I really don't like the idea of using a factory 
method or overriding opCall. Am I basically out of luck and need 
to resort to one of these methods?


More information about the Digitalmars-d-learn mailing list