I am trying to compare a list of objects called Persons for a Quicksort. The object contains strings for first name, last name, SSN, and phone number, as well as some useful members.
class Person
{
protected:
string firstname, lastname, social, birthday;
public:
Person(string, string, string, string); //store all values in strings for easy comparison and because no manipulation is necessary
~Person();
string Get(int type); //allows retrieval of protected members of object
void Print();
bool operator > (const Person& pivot) const;
//bool operator < (const Person &pivot);
};
I am trying to use operator overloading to determined which of two Person objects is larger.
bool Person::operator > (const Person& pivot) const
{
if(this->firstname > pivot.firstname)
return true;
if(this->firstname < pivot.firstname)
return false;
if(this->lastname > pivot.lastname)
return true;
if(this->lastname < pivot.lastname)
return false;
if(this->birthday > pivot.birthday)
return true;
if(this->birthday < pivot.birthday)
return false;
if(this->social > pivot.social)
return true;
if(this->social < pivot.social)
return false;
}
However, this doesn't seem to be working at all because when I run
Person * B = new Person("1234", "Donny", "Smith", "123456780");
Person * pivot = new Person("9345", "John", "Phillip", "234598765");
if (B > pivot);
cout << "hooray\n";
if(pivot > B)
cout << "Not hooray\n";
the contents of both if statements are executed. I'm thoroughly confused, but it's probably some very stupid mistake.