extern(C++) template problem

Manu turkeyman at gmail.com
Sat May 26 01:04:52 UTC 2018


On 25 May 2018 at 11:28, Walter Bright via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On 5/23/2018 10:48 AM, Manu wrote:
>>
>> Sadly, neither of these are correct.
>> The type is a class (has vtable, etc), so it is declared in D as a
>> class... It is also a class in C++, so it must mangle like a class.
>> It's also the case that it's passed by pointer, in C++ and in D. It's
>> a class that definitely behaves like a class.
>> The trouble is getting the class name into the function signature as
>> T, where the D compiler really wants to put Class* because that's the
>> type it sees a D class to be.
>
>
> One way is to create a wrapper for C in another module:
>
> ---- a.d -----
> extern (C++) class C { ... }
>
> ---- b.d -----
>
> import a;
>
> extern (C++) struct C {
>     a.C m;
>     alias m this;
> }
> --------------
>
> This relies on D regarding a.C and b.C as different symbols, even though
> they mangle the same.

Ah, interesting strategy!
Although, they don't mangle the same...

extern (C++, class) struct C { ... }

That should do it! :)


More information about the Digitalmars-d mailing list