No, you should define that in the .cpp file, don't define functions in the .h file, you might get multiple-definitions errors if you include the header in many .cpp files.
In the header files you should put only declarations, not definitions...
I made a simple example, the code works, you should play with where you put the declarations/definitions, this is the little test i made:
#include <QtCore>
#include <iostream>
struct WordItem {
WordItem(int i) : count(i) {}
int count;
};
bool compareWordItem ( const WordItem &w1 , const WordItem &w2 )
{
return w1.count > w2.count;
}
int main(int argc, char *argv[])
{
QList<WordItem> list;
list.append(10);
list.append(11);
list.append(1);
qStableSort(list.begin(),list.end(),compareWordItem);
for(QList<WordItem>::iterator i = list.begin(); i!= list.end(); ++i)
qDebug() << (*i).count;
std::cin.get();
return 0;
}
#include <QtCore>
#include <iostream>
struct WordItem {
WordItem(int i) : count(i) {}
int count;
};
bool compareWordItem ( const WordItem &w1 , const WordItem &w2 )
{
return w1.count > w2.count;
}
int main(int argc, char *argv[])
{
QList<WordItem> list;
list.append(10);
list.append(11);
list.append(1);
qStableSort(list.begin(),list.end(),compareWordItem);
for(QList<WordItem>::iterator i = list.begin(); i!= list.end(); ++i)
qDebug() << (*i).count;
std::cin.get();
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks