C++ reference return/parameter value

本文探讨了C++中通过值和引用返回对象的不同情况,详细分析了拷贝构造函数的调用时机及如何优化返回值,以减少不必要的内存分配与拷贝操作。
  1. souce C++ codes.

Point getPoint1(Point &p)
{
      Point *pp = new Point(p);
      return *pp;
}

Point &getPoint2(Point &p)
{
      Point *pp = new Point(p);
      return *pp;
}

Point getPoint3(Point p)
{
      Point *pp = new Point(p);
      return *pp;
}

Point &getPoint4(Point p)
{    
      Point *pp = new Point(p);
      return *pp;
}

int main(int argc, char *argv[])
{
    Point p0;

    Point p1 = getPoint1(p0);
    Point p2 = getPoint2(p0);
    Point p3 = getPoint1(p0);
    Point p4 = getPoint2(p0);
}

2. instructions analysis codes. (Sun C++ 5.6 Patch 117549-02 2005/02/08, SPARC)

Point getPoint1(Point &p)
{
          st      %i0,[%fp+68]               # point the space to store return value, which is allocaded by caller
          st      %i1,[%fp+72]               # point to p object
      Point *pp = new Point(p);
          call    __1c2n6FI_pv_              # call constructor function of Point()
          mov     28,%o0                     # %o0 should be the address of pp which is return above
          mov     %o0,%i5
          ld      [%fp+72],%l0               # load the beginning of p object address
          or      %g0,28,%g1                 # g0 always is 0, and 28 is the size of class Point
        1:
          subcc   %g1,4,%g1
          ld      [%l0+%g1],%l2              # load value from p
          bg      1b
          st      %l2,[%o0+%g1]              # store value (loaded from p) to pp, it's a loop operations
          st      %i5,[%fp-4]
      return *pp;
     
          ld      [%fp+68],%l1               # load the address of return Point object
          or      %g0,28,%g1
        1:
          subcc   %g1,4,%g1
          ld      [%i5+%g1],%l2              # %i5 is the beginning address of new created object pp
          bg      1b
          st      %l2,[%l1+%g1]              # store value of pp to return address
          jmp     %i7+8
          restore
}

Point &getPoint2(Point &p)
{    
          st      %i0,[%fp+68]               # point to parameter p
      Point *pp = new Point(p);
          call    __1c2n6FI_pv_
          mov     28,%o0                     # it should be %o0 = %o0 + 28
          mov     %o0,%i5
          ld      [%fp+68],%l0
          or      %g0,28,%g1
        1:
          subcc   %g1,4,%g1
          ld      [%l0+%g1],%l2
          bg      1b
          st      %l2,[%o0+%g1]              # copy parameter p to local pp
          st      %i5,[%fp-8]
      return *pp;
          ba      .L9
          mov     %i5,%i4
          mov     %i4,%i0                    # %i4 = %i5 = %o0 =  address of local pp
          jmp     %i7+8
          restore
}

Point getPoint3(Point p)
{         st      %i0,[%fp+68]              # return value object, it will be copied to really return value
          st      %i1,[%fp+72]              # p object
      Point *pp = new Point(p);
          call    __1c2n6FI_pv_
          mov     28,%o0
          mov     %o0,%i5
          ld      [%fp+72],%l0
          or      %g0,28,%g1
1:
          subcc   %g1,4,%g1
          ld      [%l0+%g1],%l2
          bg      1b
          st      %l2,[%o0+%g1]             # copy value from parameter p to local pp
          st      %i5,[%fp-4]
      return *pp;
     
          ld      [%fp+68],%l1
          or      %g0,28,%g1
1:
          subcc   %g1,4,%g1
          ld      [%i5+%g1],%l2
          bg      1b
          st      %l2,[%l1+%g1]             # copy value from local pp to temporary return space allocated by caller
          jmp     %i7+8
          restore
}

Point &getPoint4(Point p)
{         st      %i0,[%fp+68]
      Point *pp = new Point(p);
          call    __1c2n6FI_pv_
          mov     28,%o0
          mov     %o0,%i5
          ld      [%fp+68],%l0
          or      %g0,28,%g1
1:
          subcc   %g1,4,%g1
          ld      [%l0+%g1],%l2
          bg      1b
          st      %l2,[%o0+%g1]
          st      %i5,[%fp-8]
      return *pp;

          ba      .L15
          mov     %i5,%i4
          mov     %i4,%i0
          jmp     %i7+8
          restore
}

int main(int argc, char *argv[])
{
          st      %i0,[%fp+68]
          st      %i1,[%fp+72]
    Point p0;

    Point p1 = getPoint1(p0);
          add     %fp,-60,%o0               # frame of getPoint1         
          add     %fp,-32,%l1               # 60 - 32 = 28, it's the size of class Pointer; which is used in getPoint(...)
                                            # that is to say, we first allocated space
          call    __1cJgetPoint16FrnFPoint__0_
          mov     %l1,%o1                   # %l1 is the address of new allocated object;
         
    Point p2 = getPoint2(p0);               # Point &getPoint2(Point &p)
          call    __1cJgetPoint26FrnFPoint__1_
          mov     %l1,%o0
          add     %fp,-88,%l0
          or      %g0,28,%g1
1:
          subcc   %g1,4,%g1
          ld      [%o0+%g1],%l2
          bg      1b
          st      %l2,[%l0+%g1]             # copy the temporary variable to destination address
                                            # there is an assign operation, Point p1 = Point &p2;
    Point p3 = getPoint1(p0);
          add     %fp,-116,%o0
          call    __1cJgetPoint16FrnFPoint__0_
          mov     %l1,%o1
    Point p4 = getPoint2(p0);
          call    __1cJgetPoint26FrnFPoint__1_
          mov     %l1,%o0
          add     %fp,-144,%l0
          or      %g0,28,%g1
1:
          subcc   %g1,4,%g1
          ld      [%o0+%g1],%l2
          bg      1b
          st      %l2,[%l0+%g1]
}
 

/usr/local/include/opencv4/opencv2/core/cvstd_wrapper.hpp: In instantiation of ‘cv::Ptr<T>::Ptr(cv::Ptr<Y>&&) [with Y = cv::detail::MercatorWarper; T = cv::WarperCreator]’: /usr/include/c++/13/bits/invoke.h:116:38: required from ‘constexpr std::enable_if_t<is_invocable_r_v<_Res, _Callable, _Args ...>, _Res> std::__invoke_r(_Callable&&, _Args&& ...) [with _Res = cv::Ptr<cv::WarperCreator>; _Callable = main(int, char**)::<lambda()>&; _Args = {}; enable_if_t<is_invocable_r_v<_Res, _Callable, _Args ...>, _Res> = cv::Ptr<cv::WarperCreator>]’ /usr/include/c++/13/bits/std_function.h:290:30: required from ‘static _Res std::_Function_handler<_Res(_ArgTypes ...), _Functor>::_M_invoke(const std::_Any_data&, _ArgTypes&& ...) [with _Res = cv::Ptr<cv::WarperCreator>; _Functor = main(int, char**)::<lambda()>; _ArgTypes = {}]’ /usr/include/c++/13/bits/std_function.h:451:21: required from ‘std::function<_Res(_ArgTypes ...)>::function(_Functor&&) [with _Functor = main(int, char**)::<lambda()>; _Constraints = void; _Res = cv::Ptr<cv::WarperCreator>; _ArgTypes = {}]’ /home/a/stitch/stitch_diff_warper.cpp:41:22: required from here /usr/local/include/opencv4/opencv2/core/cvstd_wrapper.hpp:89:94: error: no matching function for call to ‘std::shared_ptr<cv::WarperCreator>::shared_ptr(std::remove_reference<cv::Ptr<cv::detail::MercatorWarper>&>::type)’ 89 | template<typename Y> inline Ptr(Ptr<Y>&& o) CV_NOEXCEPT : std::shared_ptr<T>(std::move(o)) {} | ^ In file included from /usr/include/c++/13/memory:80, from /usr/local/include/opencv4/opencv2/core/cvstd_wrapper.hpp:11: /usr/include/c++/13/bits/shared_ptr.h:463:9: note: candidate: ‘template<class _Alloc, class ... _Args> std::shared_ptr<_Tp>::shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Args = _Alloc; _Tp = cv::WarperCreator]’ 463 | shared_ptr(_Sp_alloc_shared_tag<_Alloc> __tag, _Args&&... __args) | ^~~~~~~~~~ /usr/include/c++/13/bits/shared_ptr.h:463:9: note: template argument deduction/substitution failed: /usr/local/include/opencv4/opencv2/core/cvstd_wrapper.hpp:89:94: note: ‘cv::Ptr<cv::detail::MercatorWarper>’ is not derived from ‘std::_Sp_alloc_shared_tag<_Tp>’ 89 | template<typename Y> inline Ptr(Ptr<Y>&& o) CV_NOEXCEPT : std::shared_ptr<T>(std::move(o)) {} | ^ /usr/include/c++/13/bits/shared_ptr.h:395:9: note: candidate: ‘template<class _Yp, class _Del, class> std::shared_ptr<_Tp>::shared_ptr(std::unique_ptr<_Up, _Ep>&&) [with _Del = _Yp; <template-parameter-2-3> = _Del; _Tp = cv::WarperCreator]’ 395 | shared_ptr(unique_ptr<_Yp, _Del>&& __r) | ^~~~~~~~~~ /usr/include/c++/13/bits/shared_ptr.h:395:9: note: template argument deduction/substitution failed: /usr/local/include/opencv4/opencv2/core/cvstd_wrapper.hpp:89:94: note: ‘std::remove_reference<cv::Ptr<cv::detail::MercatorWarper>&>::type’ {aka ‘cv::Ptr<cv::detail::MercatorWarper>’} is not derived from ‘std::unique_ptr<_Tp, _Dp>’ 89 | template<typename Y> inline Ptr(Ptr<Y>&& o) CV_NOEXCEPT : std::shared_ptr<T>(std::move(o)) {} | ^ /usr/include/c++/13/bits/shared_ptr.h:387:9: note: candidate: ‘template<class _Yp, class> std::shared_ptr<_Tp>::shared_ptr(std::auto_ptr<_Up>&&) [with _Yp = _Tp1; _Tp = cv::WarperCreator]’ 387 | shared_ptr(auto_ptr<_Yp>&& __r); | ^~~~~~~~~~ /usr/include/c++/13/bits/shared_ptr.h:387:9: note: template argument deduction/substitution failed: /usr/local/include/opencv4/opencv2/core/cvstd_wrapper.hpp:89:94: note: ‘std::remove_reference<cv::Ptr<cv::detail::MercatorWarper>&>::type’ {aka ‘cv::Ptr<cv::detail::MercatorWarper>’} is not derived from ‘std::auto_ptr<_Up>’ 89 | template<typename Y> inline Ptr(Ptr<Y>&& o) CV_NOEXCEPT : std::shared_ptr<T>(std::move(o)) {} | ^ /usr/include/c++/13/bits/shared_ptr.h:380:18: note: candidate: ‘template<class _Yp, class> std::shared_ptr<_Tp>::shared_ptr(const std::weak_ptr<_Yp>&) [with <template-parameter-2-2> = _Yp; _Tp = cv::WarperCreator]’ 380 | explicit shared_ptr(const weak_ptr<_Yp>& __r) | ^~~~~~~~~~ /usr/include/c++/13/bits/shared_ptr.h:380:18: note: template argument deduction/substitution failed: /usr/local/include/opencv4/opencv2/core/cvstd_wrapper.hpp:89:94: note: ‘std::remove_reference<cv::Ptr<cv::detail::MercatorWarper>&>::type’ {aka ‘cv::Ptr<cv::detail::MercatorWarper>’} is not derived from ‘const std::weak_ptr<_Tp>’ 89 | template<typename Y> inline Ptr(Ptr<Y>&& o) CV_NOEXCEPT : std::shared_ptr<T>(std::move(o)) {} | ^ /usr/include/c++/13/bits/shared_ptr.h:368:9: note: candidate: ‘template<class _Yp, class> std::shared_ptr<_Tp>::shared_ptr(std::shared_ptr<_Yp>&&) [with <template-parameter-2-2> = _Yp; _Tp = cv::WarperCreator]’ 368 | shared_ptr(shared_ptr<_Yp>&& __r) noexcept | ^~~~~~~~~~ /usr/include/c++/13/bits/shared_ptr.h:368:9: note: template argument deduction/substitution failed: /usr/include/c++/13/bits/shared_ptr.h: In substitution of ‘template<class _Tp> template<class ... _Args> using std::shared_ptr<_Tp>::_Constructible = typename std::enable_if<std::is_constructible<std::__shared_ptr<_Tp>, _Args ...>::value>::type [with _Args = {std::shared_ptr<cv::detail::MercatorWarper>}; _Tp = cv::WarperCreator]’: /usr/include/c++/13/bits/shared_ptr.h:367:30: required from ‘cv::Ptr<T>::Ptr(cv::Ptr<Y>&&) [with Y = cv::detail::MercatorWarper; T = cv::WarperCreator]’ /usr/include/c++/13/bits/invoke.h:116:38: required from ‘constexpr std::enable_if_t<is_invocable_r_v<_Res, _Callable, _Args ...>, _Res> std::__invoke_r(_Callable&&, _Args&& ...) [with _Res = cv::Ptr<cv::WarperCreator>; _Callable = main(int, char**)::<lambda()>&; _Args = {}; enable_if_t<is_invocable_r_v<_Res, _Callable, _Args ...>, _Res> = cv::Ptr<cv::WarperCreator>]’ /usr/include/c++/13/bits/std_function.h:290:30: required from ‘static _Res std::_Function_handler<_Res(_ArgTypes ...), _Functor>::_M_invoke(const std::_Any_data&, _ArgTypes&& ...) [with _Res = cv::Ptr<cv::WarperCreator>; _Functor = main(int, char**)::<lambda()>; _ArgTypes = {}]’ /usr/include/c++/13/bits/std_function.h:451:21: required from ‘std::function<_Res(_ArgTypes ...)>::function(_Functor&&) [with _Functor = main(int, char**)::<lambda()>; _Constraints = void; _Res = cv::Ptr<cv::WarperCreator>; _ArgTypes = {}]’ /home/a/stitch/stitch_diff_warper.cpp:41:22: required from here /usr/include/c++/13/bits/shared_ptr.h:178:15: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’ 178 | using _Constructible = typename enable_if< | ^~~~~~~~~~~~~~ /usr/local/include/opencv4/opencv2/core/cvstd_wrapper.hpp: In instantiation of ‘cv::Ptr<T>::Ptr(cv::Ptr<Y>&&) [with Y = cv::detail::MercatorWarper; T = cv::WarperCreator]’: /usr/include/c++/13/bits/invoke.h:116:38: required from ‘constexpr std::enable_if_t<is_invocable_r_v<_Res, _Callable, _Args ...>, _Res> std::__invoke_r(_Callable&&, _Args&& ...) [with _Res = cv::Ptr<cv::WarperCreator>; _Callable = main(int, char**)::<lambda()>&; _Args = {}; enable_if_t<is_invocable_r_v<_Res, _Callable, _Args ...>, _Res> = cv::Ptr<cv::WarperCreator>]’ /usr/include/c++/13/bits/std_function.h:290:30: required from ‘static _Res std::_Function_handler<_Res(_ArgTypes ...), _Functor>::_M_invoke(const std::_Any_data&, _ArgTypes&& ...) [with _Res = cv::Ptr<cv::WarperCreator>; _Functor = main(int, char**)::<lambda()>; _ArgTypes = {}]’ /usr/include/c++/13/bits/std_function.h:451:21: required from ‘std::function<_Res(_ArgTypes ...)>::function(_Functor&&) [with _Functor = main(int, char**)::<lambda()>; _Constraints = void; _Res = cv::Ptr<cv::WarperCreator>; _ArgTypes = {}]’ /home/a/stitch/stitch_diff_warper.cpp:41:22: required from here /usr/include/c++/13/bits/shared_ptr.h:351:9: note: candidate: ‘template<class _Yp, class> std::shared_ptr<_Tp>::shared_ptr(const std::shared_ptr<_Yp>&) [with <template-parameter-2-2> = _Yp; _Tp = cv::WarperCreator]’ 351 | shared_ptr(const shared_ptr<_Yp>& __r) noexcept | ^~~~~~~~~~ /usr/include/c++/13/bits/shared_ptr.h:351:9: note: template argument deduction/substitution failed: /usr/include/c++/13/bits/shared_ptr.h: In substitution of ‘template<class _Tp> template<class ... _Args> using std::shared_ptr<_Tp>::_Constructible = typename std::enable_if<std::is_constructible<std::__shared_ptr<_Tp>, _Args ...>::value>::type [with _Args = {const std::shared_ptr<cv::detail::MercatorWarper>&}; _Tp = cv::WarperCreator]’: /usr/include/c++/13/bits/shared_ptr.h:350:9: required from ‘cv::Ptr<T>::Ptr(cv::Ptr<Y>&&) [with Y = cv::detail::MercatorWarper; T = cv::WarperCreator]’ /usr/include/c++/13/bits/invoke.h:116:38: required from ‘constexpr std::enable_if_t<is_invocable_r_v<_Res, _Callable, _Args ...>, _Res> std::__invoke_r(_Callable&&, _Args&& ...) [with _Res = cv::Ptr<cv::WarperCreator>; _Callable = main(int, char**)::<lambda()>&; _Args = {}; enable_if_t<is_invocable_r_v<_Res, _Callable, _Args ...>, _Res> = cv::Ptr<cv::WarperCreator>]’ /usr/include/c++/13/bits/std_function.h:290:30: required from ‘static _Res std::_Function_handler<_Res(_ArgTypes ...), _Functor>::_M_invoke(const std::_Any_data&, _ArgTypes&& ...) [with _Res = cv::Ptr<cv::WarperCreator>; _Functor = main(int, char**)::<lambda()>; _ArgTypes = {}]’ /usr/include/c++/13/bits/std_function.h:451:21: required from ‘std::function<_Res(_ArgTypes ...)>::function(_Functor&&) [with _Functor = main(int, char**)::<lambda()>; _Constraints = void; _Res = cv::Ptr<cv::WarperCreator>; _ArgTypes = {}]’ /home/a/stitch/stitch_diff_warper.cpp:41:22: required from here /usr/include/c++/13/bits/shared_ptr.h:178:15: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’ 178 | using _Constructible = typename enable_if< | ^~~~~~~~~~~~~~ /usr/local/include/opencv4/opencv2/core/cvstd_wrapper.hpp: In instantiation of ‘cv::Ptr<T>::Ptr(cv::Ptr<Y>&&) [with Y = cv::detail::MercatorWarper; T = cv::WarperCreator]’: /usr/include/c++/13/bits/invoke.h:116:38: required from ‘constexpr std::enable_if_t<is_invocable_r_v<_Res, _Callable, _Args ...>, _Res> std::__invoke_r(_Callable&&, _Args&& ...) [with _Res = cv::Ptr<cv::WarperCreator>; _Callable = main(int, char**)::<lambda()>&; _Args = {}; enable_if_t<is_invocable_r_v<_Res, _Callable, _Args ...>, _Res> = cv::Ptr<cv::WarperCreator>]’ /usr/include/c++/13/bits/std_function.h:290:30: required from ‘static _Res std::_Function_handler<_Res(_ArgTypes ...), _Functor>::_M_invoke(const std::_Any_data&, _ArgTypes&& ...) [with _Res = cv::Ptr<cv::WarperCreator>; _Functor = main(int, char**)::<lambda()>; _ArgTypes = {}]’ /usr/include/c++/13/bits/std_function.h:451:21: required from ‘std::function<_Res(_ArgTypes ...)>::function(_Functor&&) [with _Functor = main(int, char**)::<lambda()>; _Constraints = void; _Res = cv::Ptr<cv::WarperCreator>; _ArgTypes = {}]’ /home/a/stitch/stitch_diff_warper.cpp:41:22: required from here /usr/include/c++/13/bits/shared_ptr.h:311:9: note: candidate: ‘template<class _Yp> std::shared_ptr<_Tp>::shared_ptr(const std::shared_ptr<_Yp>&, element_type*) [with _Tp = cv::WarperCreator]’ 311 | shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) noexcept | ^~~~~~~~~~ /usr/include/c++/13/bits/shared_ptr.h:311:9: note: template argument deduction/substitution failed: /usr/local/include/opencv4/opencv2/core/cvstd_wrapper.hpp:89:94: note: candidate expects 2 arguments, 1 provided 89 | template<typename Y> inline Ptr(Ptr<Y>&& o) CV_NOEXCEPT : std::shared_ptr<T>(std::move(o)) {} | ^ /usr/include/c++/13/bits/shared_ptr.h:287:9: note: candidate: ‘template<class _Deleter, class _Alloc> std::shared_ptr<_Tp>::shared_ptr(std::nullptr_t, _Deleter, _Alloc) [with _Alloc = _Deleter; _Tp = cv::WarperCreator]’ 287 | shared_ptr(nullptr_t __p, _Deleter __d, _Alloc __a) | ^~~~~~~~~~ /usr/include/c++/13/bits/shared_ptr.h:287:9: note: template argument deduction/substitution failed: /usr/local/include/opencv4/opencv2/core/cvstd_wrapper.hpp:89:94: note: candidate expects 3 arguments, 1 provided 89 | template<typename Y> inline Ptr(Ptr<Y>&& o) CV_NOEXCEPT : std::shared_ptr<T>(std::move(o)) {} | ^ /usr/include/c++/13/bits/shared_ptr.h:268:9: note: candidate: ‘template<class _Yp, class _Deleter, class _Alloc, class> std::shared_ptr<_Tp>::shared_ptr(_Yp*, _Deleter, _Alloc) [with _Deleter = _Yp; _Alloc = _Deleter; <template-parameter-2-4> = _Alloc; _Tp = cv::WarperCreator]’ 268 | shared_ptr(_Yp* __p, _Deleter __d, _Alloc __a) | ^~~~~~~~~~ /usr/include/c++/13/bits/shared_ptr.h:268:9: note: template argument deduction/substitution failed: /usr/local/include/opencv4/opencv2/core/cvstd_wrapper.hpp:89:94: note: mismatched types ‘_Yp*’ and ‘cv::Ptr<cv::detail::MercatorWarper>’ 89 | template<typename Y> inline Ptr(Ptr<Y>&& o) CV_NOEXCEPT : std::shared_ptr<T>(std::move(o)) {} | ^ /usr/include/c++/13/bits/shared_ptr.h:248:9: note: candidate: ‘template<class _Deleter> std::shared_ptr<_Tp>::shared_ptr(std::nullptr_t, _Deleter) [with _Tp = cv::WarperCreator]’ 248 | shared_ptr(nullptr_t __p, _Deleter __d) | ^~~~~~~~~~ /usr/include/c++/13/bits/shared_ptr.h:248:9: note: template argument deduction/substitution failed: /usr/local/include/opencv4/opencv2/core/cvstd_wrapper.hpp:89:94: note: candidate expects 2 arguments, 1 provided 89 | template<typename Y> inline Ptr(Ptr<Y>&& o) CV_NOEXCEPT : std::shared_ptr<T>(std::move(o)) {} | ^ /usr/include/c++/13/bits/shared_ptr.h:231:9: note: candidate: ‘template<class _Yp, class _Deleter, class> std::shared_ptr<_Tp>::shared_ptr(_Yp*, _Deleter) [with _Deleter = _Yp; <template-parameter-2-3> = _Deleter; _Tp = cv::WarperCreator]’ 231 | shared_ptr(_Yp* __p, _Deleter __d) | ^~~~~~~~~~ /usr/include/c++/13/bits/shared_ptr.h:231:9: note: template argument deduction/substitution failed: /usr/local/include/opencv4/opencv2/core/cvstd_wrapper.hpp:89:94: note: mismatched types ‘_Yp*’ and ‘cv::Ptr<cv::detail::MercatorWarper>’ 89 | template<typename Y> inline Ptr(Ptr<Y>&& o) CV_NOEXCEPT : std::shared_ptr<T>(std::move(o)) {} | ^ /usr/include/c++/13/bits/shared_ptr.h:214:9: note: candidate: ‘template<class _Yp, class> std::shared_ptr<_Tp>::shared_ptr(_Yp*) [with <template-parameter-2-2> = _Yp; _Tp = cv::WarperCreator]’ 214 | shared_ptr(_Yp* __p) : __shared_ptr<_Tp>(__p) { } | ^~~~~~~~~~ /usr/include/c++/13/bits/shared_ptr.h:214:9: note: template argument deduction/substitution failed: /usr/local/include/opencv4/opencv2/core/cvstd_wrapper.hpp:89:94: note: mismatched types ‘_Yp*’ and ‘cv::Ptr<cv::detail::MercatorWarper>’ 89 | template<typename Y> inline Ptr(Ptr<Y>&& o) CV_NOEXCEPT : std::shared_ptr<T>(std::move(o)) {} | ^ /usr/include/c++/13/bits/shared_ptr.h:535:7: note: candidate: ‘std::shared_ptr<_Tp>::shared_ptr(const std::weak_ptr<_Tp>&, std::nothrow_t) [with _Tp = cv::WarperCreator]’ 535 | shared_ptr(const weak_ptr<_Tp>& __r, std::nothrow_t) noexcept | ^~~~~~~~~~ /usr/include/c++/13/bits/shared_ptr.h:535:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/13/bits/shared_ptr.h:412:17: note: candidate: ‘constexpr std::shared_ptr<_Tp>::shared_ptr(std::nullptr_t) [with _Tp = cv::WarperCreator; std::nullptr_t = std::nullptr_t]’ 412 | constexpr shared_ptr(nullptr_t) noexcept : shared_ptr() { } | ^~~~~~~~~~ /usr/include/c++/13/bits/shared_ptr.h:412:28: note: no known conversion for argument 1 from ‘std::remove_reference<cv::Ptr<cv::detail::MercatorWarper>&>::type’ {aka ‘cv::Ptr<cv::detail::MercatorWarper>’} to ‘std::nullptr_t’ 412 | constexpr shared_ptr(nullptr_t) noexcept : shared_ptr() { } | ^~~~~~~~~ /usr/include/c++/13/bits/shared_ptr.h:359:7: note: candidate: ‘std::shared_ptr<_Tp>::shared_ptr(std::shared_ptr<_Tp>&&) [with _Tp = cv::WarperCreator]’ 359 | shared_ptr(shared_ptr&& __r) noexcept | ^~~~~~~~~~ /usr/include/c++/13/bits/shared_ptr.h:359:31: note: no known conversion for argument 1 from ‘std::remove_reference<cv::Ptr<cv::detail::MercatorWarper>&>::type’ {aka ‘cv::Ptr<cv::detail::MercatorWarper>’} to ‘std::shared_ptr<cv::WarperCreator>&&’ 359 | shared_ptr(shared_ptr&& __r) noexcept | ~~~~~~~~~~~~~^~~ /usr/include/c++/13/bits/shared_ptr.h:204:7: note: candidate: ‘std::shared_ptr<_Tp>::shared_ptr(const std::shared_ptr<_Tp>&) [with _Tp = cv::WarperCreator]’ 204 | shared_ptr(const shared_ptr&) noexcept = default; ///< Copy constructor | ^~~~~~~~~~ /usr/include/c++/13/bits/shared_ptr.h:204:18: note: no known conversion for argument 1 from ‘std::remove_reference<cv::Ptr<cv::detail::MercatorWarper>&>::type’ {aka ‘cv::Ptr<cv::detail::MercatorWarper>’} to ‘const std::shared_ptr<cv::WarperCreator>&’ 204 | shared_ptr(const shared_ptr&) noexcept = default; ///< Copy constructor | ^~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/shared_ptr.h:202:17: note: candidate: ‘constexpr std::shared_ptr<_Tp>::shared_ptr() [with _Tp = cv::WarperCreator]’ 202 | constexpr shared_ptr() noexcept : __shared_ptr<_Tp>() { } | ^~~~~~~~~~ /usr/include/c++/13/bits/shared_ptr.h:202:17: note: candidate expects 0 arguments, 1 provided In file included from /usr/include/c++/13/bits/stl_tempbuf.h:61, from /usr/include/c++/13/bits/stl_algo.h:69, from /usr/include/c++/13/algorithm:61, from /usr/local/include/opencv4/opencv2/core/base.hpp:55: /usr/include/c++/13/bits/stl_construct.h: In instantiation of ‘void std::_Construct(_Tp*, _Args&& ...) [with _Tp = cv::detail::MercatorWarper; _Args = {}]’: /usr/include/c++/13/bits/alloc_traits.h:661:19: required from ‘static void std::allocator_traits<std::allocator<void> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = cv::detail::MercatorWarper; _Args = {}; allocator_type = std::allocator<void>]’ /usr/include/c++/13/bits/shared_ptr_base.h:604:39: required from ‘std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = {}; _Tp = cv::detail::MercatorWarper; _Alloc = std::allocator<void>; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’ /usr/include/c++/13/bits/shared_ptr_base.h:971:16: required from ‘std::__shared_count<_Lp>::__shared_count(_Tp*&, std::_Sp_alloc_shared_tag<_Alloc>, _Args&& ...) [with _Tp = cv::detail::MercatorWarper; _Alloc = std::allocator<void>; _Args = {}; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’ /usr/include/c++/13/bits/shared_ptr_base.h:1712:14: required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<void>; _Args = {}; _Tp = cv::detail::MercatorWarper; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’ /usr/include/c++/13/bits/shared_ptr.h:464:59: required from ‘std::shared_ptr<_Tp>::shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<void>; _Args = {}; _Tp = cv::detail::MercatorWarper]’ /usr/include/c++/13/bits/shared_ptr.h:1009:14: required from ‘std::shared_ptr<typename std::enable_if<(! std::is_array< <template-parameter-1-1> >::value), _Tp>::type> std::make_shared(_Args&& ...) [with _Tp = cv::detail::MercatorWarper; _Args = {}; typename enable_if<(! is_array< <template-parameter-1-1> >::value), _Tp>::type = cv::detail::MercatorWarper]’ /usr/local/include/opencv4/opencv2/core/cvstd_wrapper.hpp:146:43: required from ‘cv::Ptr<_Tp> cv::makePtr(const A1& ...) [with _Tp = detail::MercatorWarper; A1 = {}]’ /home/a/stitch/stitch_diff_warper.cpp:41:70: required from here /usr/include/c++/13/bits/stl_construct.h:119:7: error: no matching function for call to ‘cv::detail::MercatorWarper::MercatorWarper()’ 119 | ::new((void*)__p) _Tp(std::forward<_Args>(__args)...); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/local/include/opencv4/opencv2/stitching/warpers.hpp:46, from /usr/local/include/opencv4/opencv2/stitching.hpp:48, from /usr/local/include/opencv4/opencv2/opencv.hpp:86: /usr/local/include/opencv4/opencv2/stitching/detail/warpers.hpp:483:5: note: candidate: ‘cv::detail::MercatorWarper::MercatorWarper(float)’ 483 | MercatorWarper(float scale) { projector_.scale = scale; } | ^~~~~~~~~~~~~~ /usr/local/include/opencv4/opencv2/stitching/detail/warpers.hpp:483:5: note: candidate expects 1 argument, 0 provided /usr/local/include/opencv4/opencv2/stitching/detail/warpers.hpp:480:18: note: candidate: ‘constexpr cv::detail::MercatorWarper::MercatorWarper(const cv::detail::MercatorWarper&)’ 480 | class CV_EXPORTS MercatorWarper : public RotationWarperBase<MercatorProjector> | ^~~~~~~~~~~~~~ /usr/local/include/opencv4/opencv2/stitching/detail/warpers.hpp:480:18: note: candidate expects 1 argument, 0 provided /usr/local/include/opencv4/opencv2/stitching/detail/warpers.hpp:480:18: note: candidate: ‘constexpr cv::detail::MercatorWarper::MercatorWarper(cv::detail::MercatorWarper&&)’ /usr/local/include/opencv4/opencv2/stitching/detail/warpers.hpp:480:18: note: candidate expects 1 argument, 0 provided make[2]: *** [CMakeFiles/stitch_diff_warper.out.dir/build.make:76:CMakeFiles/stitch_diff_warper.out.dir/stitch_diff_warper.cpp.o] 错误 1 make[1]: *** [CMakeFiles/Makefile2:83:CMakeFiles/stitch_diff_warper.out.dir/all] 错误 2 make: *** [Makefile:91:all] 错误 2
最新发布
07-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值