קוד:
struct myclass {
bool operator() (const Department &i,const Department &j) { return (i.getNumOfEmployees() <j.getNumOfEmployees());}
} help_sort;
void Company::sort_dep()
{
sort (DepList.begin(), DepList.end(), help_sort);
}
קוד:
Company.cpp: In member function ‘bool myclass::operator()(const Department&, const Department&)’:
Company.cpp:116: error: passing ‘const Department’ as ‘this’ argument of ‘int Department::getNumOfEmployees()’ discards qualifiers
Company.cpp:116: error: passing ‘const Department’ as ‘this’ argument of ‘int Department::getNumOfEmployees()’ discards qualifiers
In file included from /usr/include/c++/4.4/algorithm:62,
from Company.cpp:4:
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = std::_List_iterator<Department*>, _Compare = myclass]’:
Company.cpp:121: instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:5258: error: no match for ‘operator-’ in ‘__last - __first’
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = std::_List_iterator<Department*>, _Compare = myclass]’:
/usr/include/c++/4.4/bits/stl_algo.h:5260: instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = std::_List_iterator<Department*>, _Compare = myclass]’
Company.cpp:121: instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:2191: error: no match for ‘operator-’ in ‘__last - __first’
/usr/include/c++/4.4/bits/stl_algo.h:2193: error: no match for ‘operator+’ in ‘__first + 16’
/usr/include/c++/4.4/bits/stl_algo.h:2194: error: no match for ‘operator+’ in ‘__first + 16’
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = std::_List_iterator<Department*>, _Compare = myclass]’:
/usr/include/c++/4.4/bits/stl_algo.h:2198: instantiated from ‘void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = std::_List_iterator<Department*>, _Compare = myclass]’
/usr/include/c++/4.4/bits/stl_algo.h:5260: instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = std::_List_iterator<Department*>, _Compare = myclass]’
Company.cpp:121: instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:2124: error: no match for ‘operator+’ in ‘__first + 1’
/usr/include/c++/4.4/bits/stl_algo.h:2128: error: no match for call to ‘(myclass) (Department*&, Department*&)’
Company.cpp:116: note: candidates are: bool myclass::operator()(const Department&, const Department&)
/usr/include/c++/4.4/bits/stl_algo.h:2130: error: no match for ‘operator+’ in ‘__i + 1’
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘void std::__unguarded_linear_insert(_RandomAccessIterat or, _Tp, _Compare) [with _RandomAccessIterator = std::_List_iterator<Department*>, _Tp = Department*, _Compare = myclass]’:
/usr/include/c++/4.4/bits/stl_algo.h:2134: instantiated from ‘void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = std::_List_iterator<Department*>, _Compare = myclass]’
/usr/include/c++/4.4/bits/stl_algo.h:2198: instantiated from ‘void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = std::_List_iterator<Department*>, _Compare = myclass]’
/usr/include/c++/4.4/bits/stl_algo.h:5260: instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = std::_List_iterator<Department*>, _Compare = myclass]’
Company.cpp:121: instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:2084: error: no match for call to ‘(myclass) (Department*&, Department*&)’
Company.cpp:116: note: candidates are: bool myclass::operator()(const Department&, const Department&)