How do I call a C++ struct default constructor from D?
Atila Neves via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Feb 7 05:37:01 PST 2017
On Tuesday, 7 February 2017 at 10:46:24 UTC, kinke wrote:
> On Tuesday, 7 February 2017 at 10:15:09 UTC, Atila Neves wrote:
>> I can declare a C++ struct like so:
>>
>> extern(C++, mynamespace)
>> struct Foo {
>> //...
>> }
>>
>> But... I don't want to repeat the initialisation code for that
>> struct's default constructor. I can't declare one in D because
>> D doesn't allow default constructors for structs. What's my
>> way out? Thanks,
>>
>> Atila
>
> I'm afraid there's no way out. I summarized some of my C++
> interop findings incl. default constructor here:
> http://forum.dlang.org/thread/nqxsdehlydizatoprrax@forum.dlang.org
Ugh, I was afraid of that. I ended up having to write (!) a C++
function that returned the default-initialised struct and called
that from D.
It got uglier soon after...
I've only every done trivial C++ integration before. As soon as I
tried something "real" it all broke down incredibly fast.
Probably going to have to file some bugs on name mangling.
Atila
More information about the Digitalmars-d-learn
mailing list