Sort mit selbstgeschriebenem Vergleichsfunctor auf vector anwenden



  • Moin moin. Ich hab ein kleines Problem beim Compilieren folgenden Codes, hat jemand Ahnung was da schief läuft?:

    #include <algorithm>
    #include <functional>
    #include <utility>
    #include <vector>
    
    struct Chiquadresult
      {
      float period;
      float err_period;
      float amplitude;
      float err_amplitude;
      float magmed;
      float err_magmed;
      float fase;
      float err_fase;
      float chimin;
      float desvstchi;
      float firstmax;
      float errfirstmax;
      int pn; //minimal period searched in
      };
    
    //...
    
    class PerComptor : public binary_function<Chiquadresult,Chiquadresult,bool>
      {
      public:
      bool operator()(const Chiquadresult& lhs, const Chiquadresult& rhs)
        { return (lhs.period < rhs.period); };
      };
    
    //...
    int main()
      {
      //...
      vector<Chiquadresult> cqrtempvec();
      //vector wird gefuellt...
    
      //erstelle Comparator-Objekt:
      PerComptor pc();
    
      //sortiere den vector nach "period" der Chiquadresult-structs
      sort(cqrtempvec.begin(), cqrtempvec.end(), pc); // Zeile 155, siehe Fehlermeldung
      }
    

    An dieser Stelle spuckt er mir folgende Fehlermeldung (und einige ähnliche mehr):

    /usr/include/g++/bits/stl_heap.h: In function `void 
       std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, 
       _Compare) [with _RandomAccessIterator = 
       __gnu_cxx::__normal_iterator<Chiquadresult*, std::vector<Chiquadresult, 
       std::allocator<Chiquadresult> > >, _Distance = int, _Tp = Chiquadresult, 
       _Compare = PerComptor (*)()]':
    /usr/include/g++/bits/stl_heap.h:268:   instantiated from `void std::make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Chiquadresult*, std::vector<Chiquadresult, std::allocator<Chiquadresult> > >, _Compare = PerComptor (*)()]'
    /usr/include/g++/bits/stl_algo.h:2557:   instantiated from `void std::partial_sort(_RandomAccessIter, _RandomAccessIter, _RandomAccessIter, _Compare) [with _RandomAccessIter = __gnu_cxx::__normal_iterator<Chiquadresult*, std::vector<Chiquadresult, std::allocator<Chiquadresult> > >, _Compare = PerComptor (*)()]'
    /usr/include/g++/bits/stl_algo.h:2140:   instantiated from `void std::__introsort_loop(_RandomAccessIter, _RandomAccessIter, _Size, _Compare) [with _RandomAccessIter = __gnu_cxx::__normal_iterator<Chiquadresult*, std::vector<Chiquadresult, std::allocator<Chiquadresult> > >, _Size = int, _Compare = PerComptor (*)()]'
    /usr/include/g++/bits/stl_algo.h:2211:   instantiated from `void std::sort(_RandomAccessIter, _RandomAccessIter, _Compare) [with _RandomAccessIter = __gnu_cxx::__normal_iterator<Chiquadresult*, std::vector<Chiquadresult, std::allocator<Chiquadresult> > >, _Compare = PerComptor (*)()]'
    LC_normal.cpp:155:   instantiated from here
    /usr/include/g++/bits/stl_heap.h:187: error: too many arguments to function
    /usr/include/g++/bits/stl_heap.h:187: error: could not convert `__comp()' to `
       bool'
    


  • //erstelle Comparator-Objekt:
      PerComptor pc();
    

    Hier deklarierst du eine Funktion und erstellst kein Objekt.



  • autsch. danke 🙂


Anmelden zum Antworten