std::sort und std::deque
-
Hallo;
ich habe eine klasse erstellt.
die lade ich in ein deque<myclass> nun will ich es sorten.
gibt aber ne fehler meldung beim compilieren. und ohne der zeile
mit dem sort compiliert es es...Myclass:
class matry{ int h; int b; public: matry(void){ h=0; b=0; } bool add(int ht, int bt){ h=ht; b=bt; return h>b; } int wert(void){ return h; } friend bool operator<(matry &a, matry &b); friend bool operator==(matry &a, matry &b); }; bool operator<(matry &a, matry &b){ if(a.h<b.h and a.h!=b.h) return true; if(a.h>b.h and a.h!=b.h) return false; if(a.h==b.h and a.b<b.b) return true; if(a.h==b.h and a.b>b.b) return false; } bool operator==(matry &a, matry &b){ if(a.h==b.h) return false; if(a.b>b.b) return false; return true; }
Der sort befehl in der main:
std::deque<matry> handel; std::sort(handel.begin(), handel.end());
Compiler fehler meldung:
/usr/include/g++/bits/stl_algo.h: In function `const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&) [with _Tp = matry]': /usr/include/g++/bits/stl_algo.h:2120: instantiated from `void std::__introsort_loop(_RandomAccessIter, _RandomAccessIter, _Size) [with _RandomAccessIter = std::_Deque_iterator<matry, matry&, matry*>, _Size = int]' /usr/include/g++/bits/stl_algo.h:2180: instantiated from `void std::sort(_RandomAccessIter, _RandomAccessIter) [with _RandomAccessIter = std::_Deque_iterator<matry, matry&, matry*>]' prog4.cpp:64: instantiated from here /usr/include/g++/bits/stl_algo.h:90: error: no match for 'operator<' in '__a < __b' prog4.cpp:21: error: candidates are: bool operator<(matry&, matry&) /usr/include/g++/bits/stl_algo.h:91: error: no match for 'operator<' in '__b < __c' prog4.cpp:21: error: candidates are: bool operator<(matry&, matry&) /usr/include/g++/bits/stl_algo.h:93: error: no match for 'operator<' in '__a < __c' prog4.cpp:21: error: candidates are: bool operator<(matry&, matry&) /usr/include/g++/bits/stl_algo.h:97: error: no match for 'operator<' in '__a < __c' prog4.cpp:21: error: candidates are: bool operator<(matry&, matry&) /usr/include/g++/bits/stl_algo.h:99: error: no match for 'operator<' in '__b < __c' prog4.cpp:21: error: candidates are: bool operator<(matry&, matry&)
Die header dateien hab ich eingebunden.
Hat jemand ne idee? Ich hab doch ein operator<!MFG Ghost
-
Bei den Operatoren, übergib mal die Parameter als const Referenz.
-
THX