On Sunday, 15 March 2020 at 21:27:32 UTC, Ferhat Kurtulmuş wrote:
On Sunday, 15 March 2020 at 21:16:43 UTC, Arine wrote:
On Sunday, 15 March 2020 at 20:53:49 UTC, Ferhat Kurtulmuş

I wouldn't use a class on the D side, unless your C++ type uses virtual functions. Classes in D are different from structs, it is not the same as C++ where they are basically the same thing.

I know their differences, classes are reference types and structs are value types in D.

That's not the only difference. It's why your code doesn't work.

I actually don't need this code. I've already wrapped many c code, but have no so much experience with interfacing C++ code. I am trying to understand capabilities of D in interfacing with C++ and its limits. I would like to know why I can interface a template-free class, but not a class template.

You can, you just aren't representing the C++ code properly in D. You don't want class, it means something different in D than in C++.

This works for me, as it is using struct that corresponds to the C++ type. You have to use extern(C++, class), as it is using "class" on the C++ side, which produces a different mangling.

extern(C++, cv){
extern(C++, class) struct Size_(_Tp){
    @disable this();
        ~this() { }

    final _Tp area() const;
    final double aspectRatio() const;
    final bool empty() const;

    _Tp width; //!< the width
    _Tp height; //!< the height
}
}

extern(C++){
    cv.Size_!int* createSizeIntWH(int w, int h);
}

void main()
{
        Size_!int* sz = createSizeIntWH(200, 100);
        writeln(sz.width);
}

Reply via email to