用C++对对象矢量进行排序

Adr*_*ian 0 c++

struct Keyword
{
    std::string keyword;
    int numUses;
};  

bool sortingVector(const Keyword& key1, const Keyword& key2)
{
    return key1.numUses < key2.numUses;
}

sort(topKeywords.begin(), topKeywords.end(), sortingVector);



: no matching function for call to 'sort(std::vector<Keyword>::iterator, std::vector<Keyword>::iterator, <unresolved overloaded function type>)'
        c:\mingw\bin\../lib/gcc/mingw32/4.5.0/include/c++/bits/stl_algo.h:5236:18: note: candidate is: void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<Keyword*, std::vector<Keyword> >, _Compare = bool (NewsAggregatorImpl::*)(const Keyword&, const Keyword&)]
Run Code Online (Sandbox Code Playgroud)

为什么这不正确,我的编译器给了我那个错误.
我希望我的功能是全球性的.
谢谢.

Jer*_*ock 6

sortingVector某类的非静态成员吗​​?错误消息表明它是,在这种情况下,您将需要将其包装(boost::bind例如,使用)到不带this参数的二进制操作.您可能想要创建sortingVector静态成员或自由函数.