What is the wrong with my C++ interfacing
drug
drug2004 at bk.ru
Sun Mar 15 20:21:57 UTC 2020
15.03.2020 22:39, Ferhat Kurtulmuş пишет:
>
> 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);
What is the D version of `createSizeIntWH`? In C++ it returns a pointer
but in D version it returns an instance.
>
> 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_ at 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?
>
More information about the Digitalmars-d-learn
mailing list