Jak sortować wzgledem strPhoneNumber w ponizszym przypadku?
struct ContactItem
{
string strContactsName;
string strPhoneNumber;
ContactItem(const string& strName, const string & strNumber)
{
strContactsName = strName;
strPhoneNumber = strNumber;
}
bool operator == (const ContactItem& itemToCompare) const
{
return (itemToCompare.strContactsName == this->strContactsName);
}
bool operator < (const ContactItem& itemToCompare) const
{
return (this->strContactsName < itemToCompare.strContactsName);
}
};
void FindContact(const set <ContactItem>& setContacts);
void FindContactByNumber(const set <ContactItem>& setContacts);
void FindContact(const set <ContactItem>& setContacts)
{
cout << "*** Wyszukanie danych kontaktowych ***" << endl;
cout << "Czyj numer telefonu chcialbys znalezc?" << endl;
cout << "> ";
string strName;
cin >> strName;
set <ContactItem>::const_iterator iContactFound
= setContacts.find(ContactItem(strName, ""));
if (iContactFound != setContacts.end())
{
cout << strName << " jest dostepny pod numerem telefonu: ";
cout << iContactFound->strPhoneNumber << endl;
}
else
cout << strName << " nie zostal znaleziony na liscie kontaktow" << endl;
cout << endl;
return;
}
void FindContactByNumber(const set <ContactItem>& setContacts)
{
cout << "Znajdz imie kontaktu po numerze telefonu!" << endl;
cout << "Wpisz numer telefonu" << endl;
cout << ">";
string strPhoneNumber;
cin >> strPhoneNumber;
set <ContactItem>::const_iterator iContactFound
= setContacts.find(ContactItem("", strPhoneNumber));
if (iContactFound != setContacts.end())
{
cout << strPhoneNumber << " jest numerem telefonu do: ";
cout << iContactFound->strContactsName << endl;
}
else
{
cout << "Kontakt o podanym numerze telefonu nie zostal znaleziony!" << endl;
}
}
W funkcji FindContactByNumber muszę dodać predykat sortowania, który przesłoni operator < i domyślne sortowanie na nim bazujące lecz nie wiem jak to zrobić.