I am trying to store email addresses written in a file and sort them by hits in the file.
I am storing the email addresses and the number of hits in a class called emailAddress.
I am managing the members of that class in a Deque in another class called AddressManager.
The sort function I am trying to use is the sort from the algorithm library. Like this.
[emailAddress.released() returns the number of hits. addressQueue is my emailAddress Deque]
bool AddressManager::swapTest(const emailAddress& address1, const emailAddress& address2)
{
cout<<"Comparing: "<<address1.released()<<" to "<<address2.released()<<endl;
return address1.released()>address2.released();
}
void AddressManager::sortAddresses()
{
sort(addressQueue.begin(),addressQueue.end(),
swapTest);
}
When I compile I get this error:
1>c:\workspace\addressmanager.cpp(36): error C3867: 'AddressManager::swapTest': function call missing argument list; use '&AddressManager::swapTest' to create a pointer to member
1>c:\workspace\addressmanager.cpp(36): error C2780: 'void std::sort(_RanIt,_RanIt)' : expects 2 arguments - 3 provided
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm(3639) : see declaration of 'std::sort'
Can I pass swapTest to sort, or does it need to be defined outside of AddressManager somehow?
Or could someone suggest a way to implement my own sort in AddressManager and not use the library version at all?
Thanks,
ANkh
Just define an
and pass it to
std::sortOr make swapTest a static function and do
std::sort( v.begin() , v.end() , &AddressManager::swapTest );