Die Zeile sort (mRows.begin(), mRows.end(), cmp_cdhsrow); verursacht die vielen Fehler!.
Code: Alles auswählen
#include <vector>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <sstream>
using namespace std;
class CDHSRow
{
protected:
vector<string> mFields;
vector<int> mLens;
vector<int> mIdx;
public:
void addField (int idx, const char *data, int size);
bool operator< (const CDHSRow &a)
{ return mFields[0] < a.mFields[0]; }
bool operator== (const CDHSRow &a)
{ return mFields[0] == a.mFields[0]; }
};
void CDHSRow::addField (int idx, const char *data, int size)
{
string field (data, size);
mFields.push_back(field);
mLens.push_back(size);
mIdx.push_back(idx);
}
bool cmp_cdhsrow (CDHSRow &a, CDHSRow &b)
{
return a < b;
}
int main(int, char **)
{
vector<CDHSRow> mRows;
// einige Zeilen mRows einfügen... anschliessend sortieren
sort (mRows.begin(), mRows.end(), cmp_cdhsrow);
return 0;
}
Code: Alles auswählen
cd '.../testsort/debug' && WANT_AUTOCONF_2_5="1" WANT_AUTOMAKE_1_6="1" make -k
make all-recursive
Making all in src
compiling testsort.cpp (g++)
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h: In function ‘const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&, _Compare) [with _Tp = CDHSRow, _Compare = bool (*)(CDHSRow&, CDHSRow&)]’:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:2679: instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<CDHSRow*, std::vector<CDHSRow, std::allocator<CDHSRow> > >, _Size = int, _Compare = bool (*)(CDHSRow&, CDHSRow&)]’
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:2749: instantiated from ‘void std::sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<CDHSRow*, std::vector<CDHSRow, std::allocator<CDHSRow> > >, _Compare = bool (*)(CDHSRow&, CDHSRow&)]’
.../testsort/src/testsort.cpp:45: instantiated from here
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:125: error: invalid initialization of reference of type ‘CDHSRow&’ from expression of type ‘const CDHSRow’
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:126: error: invalid initialization of reference of type ‘CDHSRow&’ from expression of type ‘const CDHSRow’
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:128: error: invalid initialization of reference of type ‘CDHSRow&’ from expression of type ‘const CDHSRow’
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:132: error: invalid initialization of reference of type ‘CDHSRow&’ from expression of type ‘const CDHSRow’
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:134: error: invalid initialization of reference of type ‘CDHSRow&’ from expression of type ‘const CDHSRow’
make[2]: *** [testsort.o] Error 1
make[2]: Target `all' not remade because of errors.
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
*** Exited with status: 2 ***
Kann mir wieder jemand weiterhelfen? - Besten Dank schon im Voraus!
- Adrian