C++ binding issues with C++ function returning a simple POD struct.

evilrat via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 22 18:14:28 PDT 2017


On Monday, 22 May 2017 at 18:51:43 UTC, ParticlePeter wrote:
> On Monday, 22 May 2017 at 14:01:56 UTC, Jerry wrote:
>
>> IIRC the problem is that it isn't a POD type. ImVec2 has its 
>> own default constructor. The problem now is that because it no 
>> longer is POD, Window's ABI handles it different and doesn't 
>> put the value in a register. Now with D is that you aren't 
>> allowed to specify your own default constructor, so there's no 
>> equivalent way for it to know that it isn't a POD. A way 
>> around this is to specify your own destructor or copy 
>> constructor in the D ImVec2. I forget what the rules are for 
>> it, but I think that should do it.
>
> Thanks, with any of them, ~this or this(this) (both can be 
> empty), the functions work as expected, nice.
>
> Also replying your next post, extern(C++) is on for the whole 
> module:
> https://github.com/ParticlePeter/imgui_lib/blob/master/source/imgui/types.d#L39
>
> but I learned how to link to github lines from your post :-)

Better check if empty postblit('this(this)' ctor) works well when 
assign structs though. It would be annoying if passing and 
assigning structs on D side would do something weird.

And, if it works I should probably do this for DirectX bindings 
as well instead of hack.


More information about the Digitalmars-d-learn mailing list