简体   繁体   中英

std::sort for a vector raise error on sorting custom object

I am trying to sort a vector of defined objects using std::sort. However, I ran into long list of errors.I have tried to spot something out of the log and change. I believe there has to be something with comparison operator. Is there any thing could be spotted from the log?!

std::vector<ShapeDescriptor> bins;
bins = objects.getBinsInRange(DEFAULT_BIN, cWest, endNorth);
// sort using a custom function object
std::sort(bins.begin(), bins.end(), 
[](ShapeDescriptor a, ShapeDescriptor b)
{return a.getPosition().x < b.getPosition().x;});

The error log is

g++ -g -Wall -std=c++17 -o main  main.cpp Detector.cpp Shape.cpp `pkg-config --cflags --libs opencv `
In file included from /usr/include/c++/7/functional:64:0,
                 from Detector.h:5,
                 from Detector.cpp:1:
/usr/include/c++/7/bits/stl_algo.h: In instantiation of ‘void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’:
/usr/include/c++/7/bits/stl_algo.h:1885:25:   required from ‘void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:1971:31:   required from ‘void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:4868:18:   required from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)>]’
Detector.cpp:66:100:   required from here
/usr/include/c++/7/bits/stl_algo.h:1852:17: error: use of deleted function ‘ShapeDescriptor& ShapeDescriptor::operator=(ShapeDescriptor&&)’
        *__first = _GLIBCXX_MOVE(__val);
                 ^
In file included from Detector.h:7:0,
                 from Detector.cpp:1:
Shape.h:31:7: note: ‘ShapeDescriptor& ShapeDescriptor::operator=(ShapeDescriptor&&)’ is implicitly deleted because the default definition would be ill-formed:
 class ShapeDescriptor {
       ^~~~~~~~~~~~~~~
Shape.h:31:7: error: non-static const member ‘const double ShapeDescriptor::SQUARE_RATIO_L_LIMIT’, can’t use default assignment operator
Shape.h:31:7: error: non-static const member ‘const double ShapeDescriptor::SQUARE_RATIO_U_LIMIT’, can’t use default assignment operator
In file included from /usr/include/c++/7/bits/stl_algo.h:61:0,
                 from /usr/include/c++/7/functional:64,
                 from Detector.h:5,
                 from Detector.cpp:1:
/usr/include/c++/7/bits/stl_heap.h: In instantiation of ‘void std::__pop_heap(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’:
/usr/include/c++/7/bits/stl_algo.h:1675:19:   required from ‘void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:1933:25:   required from ‘void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:1948:27:   required from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:1968:25:   required from ‘void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:4868:18:   required from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)>]’
Detector.cpp:66:100:   required from here
/usr/include/c++/7/bits/stl_heap.h:252:17: error: use of deleted function ‘ShapeDescriptor& ShapeDescriptor::operator=(ShapeDescriptor&&)’
       *__result = _GLIBCXX_MOVE(*__first);
                 ^
In file included from /usr/include/c++/7/memory:62:0,
                 from Detector.h:4,
                 from Detector.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h: In instantiation of ‘void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _ForwardIterator2 = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >]’:
/usr/include/c++/7/bits/stl_algo.h:84:20:   required from ‘void std::__move_median_to_first(_Iterator, _Iterator, _Iterator, _Iterator, _Compare) [with _Iterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:1921:34:   required from ‘_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:1953:38:   required from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:1968:25:   required from ‘void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:4868:18:   required from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)>]’
Detector.cpp:66:100:   required from here
/usr/include/c++/7/bits/stl_algobase.h:148:11: error: no matching function for call to ‘swap(ShapeDescriptor&, ShapeDescriptor&)’
       swap(*__a, *__b);
       ~~~~^~~~~~~~~~~~
In file included from /usr/include/c++/7/bits/stl_pair.h:59:0,
                 from /usr/include/c++/7/bits/stl_algobase.h:64,
                 from /usr/include/c++/7/memory:62,
                 from Detector.h:4,
                 from Detector.cpp:1:
/usr/include/c++/7/bits/move.h:187:5: note: candidate: template<class _Tp> typename std::enable_if<std::__and_<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> >::value>::type std::swap(_Tp&, _Tp&)
     swap(_Tp& __a, _Tp& __b)
     ^~~~
/usr/include/c++/7/bits/move.h:187:5: note:   template argument deduction/substitution failed:
/usr/include/c++/7/bits/move.h: In substitution of ‘template<class _Tp> typename std::enable_if<std::__and_<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> >::value>::type std::swap(_Tp&, _Tp&) [with _Tp = ShapeDescriptor]’:
/usr/include/c++/7/bits/stl_algobase.h:148:11:   required from ‘void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _ForwardIterator2 = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >]’
/usr/include/c++/7/bits/stl_algo.h:84:20:   required from ‘void std::__move_median_to_first(_Iterator, _Iterator, _Iterator, _Iterator, _Compare) [with _Iterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:1921:34:   required from ‘_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:1953:38:   required from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:1968:25:   required from ‘void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:4868:18:   required from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)>]’
Detector.cpp:66:100:   required from here
/usr/include/c++/7/bits/move.h:187:5: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’
/usr/include/c++/7/bits/stl_algobase.h: In instantiation of ‘void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _ForwardIterator2 = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >]’:
/usr/include/c++/7/bits/stl_algo.h:84:20:   required from ‘void std::__move_median_to_first(_Iterator, _Iterator, _Iterator, _Iterator, _Compare) [with _Iterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:1921:34:   required from ‘_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:1953:38:   required from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:1968:25:   required from ‘void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:4868:18:   required from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)>]’
Detector.cpp:66:100:   required from here
/usr/include/c++/7/bits/move.h:210:5: note: candidate: template<class _Tp, long unsigned int _Nm> typename std::enable_if<std::__is_swappable<_Tp>::value>::type std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm])
     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
     ^~~~
/usr/include/c++/7/bits/move.h:210:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/7/memory:62:0,
                 from Detector.h:4,
                 from Detector.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:148:11: note:   mismatched types ‘_Tp [_Nm]’ and ‘ShapeDescriptor’
       swap(*__a, *__b);
       ~~~~^~~~~~~~~~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/7/memory:62,
                 from Detector.h:4,
                 from Detector.cpp:1:
/usr/include/c++/7/bits/stl_pair.h:490:5: note: candidate: template<class _T1, class _T2> typename std::enable_if<std::__and_<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value>::type std::swap(std::pair<_T1, _T2>&, std::pair<_T1, _T2>&)
     swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
     ^~~~
/usr/include/c++/7/bits/stl_pair.h:490:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/7/memory:62:0,
                 from Detector.h:4,
                 from Detector.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:148:11: note:   ‘ShapeDescriptor’ is not derived from ‘std::pair<_T1, _T2>’
       swap(*__a, *__b);
       ~~~~^~~~~~~~~~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/7/memory:62,
                 from Detector.h:4,
                 from Detector.cpp:1:
/usr/include/c++/7/bits/stl_pair.h:498:5: note: candidate: template<class _T1, class _T2> typename std::enable_if<(! std::__and_<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value)>::type std::swap(std::pair<_T1, _T2>&, std::pair<_T1, _T2>&) <deleted>
     swap(pair<_T1, _T2>&, pair<_T1, _T2>&) = delete;
     ^~~~
/usr/include/c++/7/bits/stl_pair.h:498:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/7/memory:62:0,
                 from Detector.h:4,
                 from Detector.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:148:11: note:   ‘ShapeDescriptor’ is not derived from ‘std::pair<_T1, _T2>’
       swap(*__a, *__b);
       ~~~~^~~~~~~~~~~~
In file included from /usr/include/c++/7/bits/stl_algo.h:61:0,
                 from /usr/include/c++/7/functional:64,
                 from Detector.h:5,
                 from Detector.cpp:1:
/usr/include/c++/7/bits/stl_heap.h: In instantiation of ‘void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Distance = long int; _Tp = ShapeDescriptor; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’:
/usr/include/c++/7/bits/stl_heap.h:342:22:   required from ‘void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:1672:23:   required from ‘void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:1933:25:   required from ‘void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:1948:27:   required from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:1968:25:   required from ‘void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:4868:18:   required from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)>]’
Detector.cpp:66:100:   required from here
/usr/include/c++/7/bits/stl_heap.h:225:29: error: use of deleted function ‘ShapeDescriptor& ShapeDescriptor::operator=(ShapeDescriptor&&)’
    *(__first + __holeIndex) = _GLIBCXX_MOVE(*(__first + __secondChild));
                             ^
/usr/include/c++/7/bits/stl_heap.h:231:29: error: use of deleted function ‘ShapeDescriptor& ShapeDescriptor::operator=(ShapeDescriptor&&)’
    *(__first + __holeIndex) = _GLIBCXX_MOVE(*(__first
                             ^
In file included from /usr/include/c++/7/memory:62:0,
                 from Detector.h:4,
                 from Detector.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h: In instantiation of ‘static _BI2 std::__copy_move_backward<true, false, std::random_access_iterator_tag>::__copy_move_b(_BI1, _BI1, _BI2) [with _BI1 = ShapeDescriptor*; _BI2 = ShapeDescriptor*]’:
/usr/include/c++/7/bits/stl_algobase.h:588:58:   required from ‘_BI2 std::__copy_move_backward_a(_BI1, _BI1, _BI2) [with bool _IsMove = true; _BI1 = ShapeDescriptor*; _BI2 = ShapeDescriptor*]’
/usr/include/c++/7/bits/stl_algobase.h:598:5:   required from ‘_BI2 std::__copy_move_backward_a2(_BI1, _BI1, _BI2) [with bool _IsMove = true; _BI1 = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _BI2 = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >]’
/usr/include/c++/7/bits/stl_algobase.h:668:48:   required from ‘_BI2 std::move_backward(_BI1, _BI1, _BI2) [with _BI1 = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _BI2 = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >]’
/usr/include/c++/7/bits/stl_algo.h:1851:8:   required from ‘void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:1885:25:   required from ‘void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:1971:31:   required from ‘void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’
/usr/include/c++/7/bits/stl_algo.h:4868:18:   required from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)>]’
Detector.cpp:66:100:   required from here
/usr/include/c++/7/bits/stl_algobase.h:548:18: error: use of deleted function ‘ShapeDescriptor& ShapeDescriptor::operator=(ShapeDescriptor&&)’
      *--__result = std::move(*--__last);
      ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/bits/stl_algo.h:61:0,
                 from /usr/include/c++/7/functional:64,
                 from Detector.h:5,
                 from Detector.cpp:1:
/usr/include/c++/7/bits/stl_heap.h:128:5: warning: ‘void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Distance = long int; _Tp = ShapeDescriptor; _Compare = __gnu_cxx::__ops::_Iter_comp_val<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’ used but never defined
     __push_heap(_RandomAccessIterator __first,
     ^~~~~~~~~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:71:0,
                 from /usr/include/c++/7/memory:62,
                 from Detector.h:4,
                 from Detector.cpp:1:
/usr/include/c++/7/bits/predefined_ops.h:169:7: warning: ‘__gnu_cxx::__ops::_Iter_comp_val<_Compare>::_Iter_comp_val(__gnu_cxx::__ops::_Iter_comp_iter<_Compare>&&) [with _Compare = Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)>]’ used but never defined
       _Iter_comp_val(_Iter_comp_iter<_Compare>&& __comp)
       ^~~~~~~~~~~~~~
In file included from /usr/include/c++/7/functional:64:0,
                 from Detector.h:5,
                 from Detector.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:1821:5: warning: ‘void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ShapeDescriptor*, std::vector<ShapeDescriptor> >; _Compare = __gnu_cxx::__ops::_Val_comp_iter<Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)> >]’ used but never defined
     __unguarded_linear_insert(_RandomAccessIterator __last,
     ^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:71:0,
                 from /usr/include/c++/7/memory:62,
                 from Detector.h:4,
                 from Detector.cpp:1:
/usr/include/c++/7/bits/predefined_ops.h:225:5: warning: ‘__gnu_cxx::__ops::_Val_comp_iter<_Compare> __gnu_cxx::__ops::__val_comp_iter(__gnu_cxx::__ops::_Iter_comp_iter<_Compare>) [with _Compare = Detector::evaluate()::<lambda(ShapeDescriptor, ShapeDescriptor)>]’ used but never defined
     __val_comp_iter(_Iter_comp_iter<_Compare> __comp)
     ^~~~~~~~~~~~~~~
makefile:11: recipe for target 'main' failed
make: *** [main] Error 1

The Shape.cpp is

#include "Shape.h"

ShapeDescriptor::ShapeDescriptor(){
    _type = UNDEFINED;
}

void ShapeDescriptor::copyFrom(const ShapeDescriptor &copy)
{
    _contour = copy._contour;    
    _type = copy._type;
    bounder = copy.bounder; 
}

ShapeDescriptor::ShapeDescriptor(std::vector<cv::Point> contour):
_contour{std::move(contour)}
{
   _type = UNDEFINED; 

   estimateShape();
   computePosition();
}

std::vector<cv::Point> ShapeDescriptor::getContour(){
    return _contour;
}

void ShapeDescriptor::estimateShape(){
    double peri = cv::arcLength( _contour, true);
    std::vector<cv::Point> approx;
    cv::approxPolyDP(_contour, approx, 0.04 * peri, true);
    int vertices = approx.size();
    bounder = cv::boundingRect(approx);

    if (getSize() < 25){
        return;
    }
    if (vertices == 3){
        _type = TRIANGLE;
    }
    else if (vertices == 4){
        double ratio = bounder.width/(double)bounder.height;

        if ((SQUARE_RATIO_L_LIMIT <= ratio) &&
                (ratio <= SQUARE_RATIO_U_LIMIT)) {
            _type = SQUARE;
        }else{
            _type = RECTANGLE;
        }
    }
    else if (vertices == 5){
        _type = POLYGON;
    }
    else{
        _type = CIRCLE;
    }

}


cv::Point ShapeDescriptor::ulCorner(){
    return cv::Point(bounder.x, bounder.y);
}

cv::Point ShapeDescriptor::urCorner(){
    return cv::Point(bounder.x + bounder.width,
            bounder.y);
}

cv::Point ShapeDescriptor::drCorner(){
    return cv::Point(bounder.x + bounder.width, 
            bounder.y + bounder.height);
}

cv::Point ShapeDescriptor::rEdge(){
    return cv::Point(bounder.x + bounder.width,
            bounder.y + bounder.height/2);
}

double ShapeDescriptor::getWidth(){
    return bounder.width;
}

double ShapeDescriptor::getHeight(){
    return bounder.height;
}

void ShapeDescriptor::computePosition(){
    _pos = cv::Point(bounder.x + bounder.width/2,
            bounder.y + bounder.height/2);
}
cv::Point ShapeDescriptor::getPosition(){
    return _pos;
}

Shape ShapeDescriptor::getType(){
    return _type;
}

double ShapeDescriptor::getSize(){
    return bounder.width * bounder.height;
}

void ShapeDescriptor::highlight(cv::Mat ref_img,
        cv::Scalar bc,
        cv::Scalar cc){
    std::vector<std::vector<cv::Point>> v;
    v.push_back(_contour);
    cv::drawContours(ref_img, v, 0, bc, 2);
    cv::circle(ref_img, _pos, 1, cc, -1);
}

bool ShapeDescriptor::isType(int s){
    return _type == s;
}

Shape.h

#ifndef ShapeDescriptor_hpp
#define ShapeDescriptor_hpp

#include <tuple>
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/imgproc.hpp>

enum Shape {
    UNDEFINED = 0,
    CIRCLE = 1,
    SQUARE = 2,
    POLYGON = 3,
    TRIANGLE = 4,
    RECTANGLE = 5
};

class Color{
    public:
        static cv::Scalar GREEN;
        static cv::Scalar RED;
        static cv::Scalar BLUE; 
        static cv::Scalar WHITE; 
};

class ShapeDescriptor {

    private:
        const double SQUARE_RATIO_L_LIMIT = 0.70;
        const double SQUARE_RATIO_U_LIMIT = 1.5;  

        cv::Rect bounder;
        std::vector<cv::Point> _contour;
        cv::Point _pos;
        Shape _type;


        void computePosition();
        void estimateShape();

    public: 
        ShapeDescriptor();
        ShapeDescriptor(std::vector<cv::Point>);

        void copyFrom(const ShapeDescriptor&x);
        bool isType(int);

        void highlight(cv::Mat, cv::Scalar, cv::Scalar);

        cv::Point ulCorner();

        cv::Point drCorner();

        cv::Point urCorner();

        cv::Point rEdge();

        double getSize();
        std::vector<cv::Point> getContour(); 
        cv::Point getPosition();

        Shape getType();

        double getWidth();
        double getHeight(); 

};
#endif /* Shape_hpp */

The first error message stems from the missing move assignment operator for ShapeDescriptor:

error: use of deleted function ‘ShapeDescriptor& ShapeDescriptor::operator=(ShapeDescriptor&&)’

It also gives you a note why there is no implicit move assignment operator:

Shape.h:31:7: note: ‘ShapeDescriptor& ShapeDescriptor::operator=(ShapeDescriptor&&)’ is implicitly deleted because the default definition would be ill-formed:
 class ShapeDescriptor {
       ^~~~~~~~~~~~~~~
Shape.h:31:7: error: non-static const member ‘const double ShapeDescriptor::SQUARE_RATIO_L_LIMIT’, can’t use default assignment operator
Shape.h:31:7: error: non-static const member ‘const double ShapeDescriptor::SQUARE_RATIO_U_LIMIT’, can’t use default assignment operator

This means the class has const members, so the compiler cannot generate any assignment operator itself. Note that in order to sort a sequence, the compiler must swap the elements, and this requires the class to be move-assignable and move-constructible by default . You could also implement a swap function for ShapeDescriptors .

Your comparison is probably OK, but depending on the size of ShapeDescriptor it may be more efficient to take the arguments to be compared by const reference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM