extern(C++) template problem

Walter Bright newshound2 at digitalmars.com
Fri May 25 18:28:10 UTC 2018


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.


More information about the Digitalmars-d mailing list