The original C++ class https://github.com/opencv/opencv/blob/master/modules/core/include/opencv2/core/types.hpp#L315: template<typename _Tp> class Size_ { public: typedef _Tp value_type; //! default constructor Size_(); Size_(_Tp _width, _Tp _height); Size_(const Size_& sz); Size_(Size_&& sz) CV_NOEXCEPT; Size_(const Point_<_Tp>& pt); Size_& operator = (const Size_& sz); Size_& operator = (Size_&& sz) CV_NOEXCEPT; //! the area (width*height) _Tp area() const; //! aspect ratio (width/height) double aspectRatio() const; //! true if empty bool empty() const; //! conversion of another data type. template<typename _Tp2> operator Size_<_Tp2>() const; _Tp width; //!< the width _Tp height; //!< the height }; // my auxiliary cpp code: cv::Size_<int>* createSizeIntWH(int _width, int _height){ return new cv::Size_<int>(_width, _height); } void deleteSizeInt(cv::Size_<int> *&sz){ delete sz; } // d code: extern(C++, cv){ class Size_(_Tp){ @disable this(); final _Tp area() const; final double aspectRatio() const; final bool empty() const; _Tp width; //!< the width _Tp height; //!< the height } } // my test code that fails: Size_!int sz = createSizeIntWH(200, 100); writeln(sz.width);One of the problems is that sz.width is not printed as 200, but a random int. Other problem is that if I try to call one of area, aspectRatio, and empty, it does not compile yielding a linker error: error LNK2019: unresolved external symbol "public: int __cdecl cv::Size_<int>::area(void)const " (?area@?$Size_@H@cv@@QEBAHXZ) referenced in function _Dmain Somehow linker cannot locate that symbol. Is this a name mangling issue? In the same library I could successfully interface cv::Mat which is a template-free definition. I suspect if D allows interfacing C++ class templates since docs do not cover this, but only struct templates?
What is the wrong with my C++ interfacing
Ferhat Kurtulmuş via Digitalmars-d-learn Sun, 15 Mar 2020 12:41:21 -0700
- What is the wrong with my C++ in... Ferhat Kurtulmuş via Digitalmars-d-learn
- Re: What is the wrong with ... drug via Digitalmars-d-learn
- Re: What is the wrong w... Ferhat Kurtulmuş via Digitalmars-d-learn
- Re: What is the wro... drug via Digitalmars-d-learn
- Re: What is the... Ferhat Kurtulmuş via Digitalmars-d-learn
- Re: What i... drug via Digitalmars-d-learn
- Re: What i... Arine via Digitalmars-d-learn