struct Keyword
{
std::string keyword;
int numUses;
};
bool sortingVector(const Keyword& key1, const Keyword& key2)
{
return key1.numUses < key2
This is what a compilable example should look like:
Because you did not provide the exact code that was generating the errors people have given a couple of different types of answer. As a result it is generally a good idea to generate a compilable example the displays the problem.
#include
#include
#include
struct Keyword
{
std::string keyword;
int numUses;
};
bool sortingVector(const Keyword& key1, const Keyword& key2)
{
return key1.numUses < key2.numUses;
}
int main()
{
std::vector topKeywords;
std::sort(topKeywords.begin(), topKeywords.end(), sortingVector);
}
Generally the compiler can do a better job of optimising (I am told) if you use a functor rather than a function pointer.
struct SortingVectorFunctor
{
bool operator()(const Keyword& key1, const Keyword& key2) const
{
return key1.numUses < key2.numUses;
}
};