//---------------------------------------------------------------- // // overload.cpp // // A program that overloads an operator. // // written by: Simon Parsons // modified : 30th April 2010 // //---------------------------------------------------------------- #include using namespace std; //---------------------------------------------------------------- // // person // The class person has data about a human being class person { private: string first_name; string second_name; int age; public: person(string, string, int); void print(); // An overloaded operator bool operator>(person); }; // Constructor person::person(string first, string last, int age){ first_name = first; second_name = last; this->age = age; } void person::print(){ cout << first_name << " " << second_name << endl; } bool person::operator>(person p){ if (this->age > p.age){ return true; } else { return false; } } // End of person person older(person a, person b){ if (a > b){ return a; } else { return b; } } //---------------------------------------------------------------- // // Main program // This creates two instances of person, prints them out, finds the // older and prints that one out again. int main() { person harry("harry", "potter", 12); person hermie("hermionie","granger", 13); harry.print(); hermie.print(); cout << "The older of the two is: "; older(harry,hermie).print(); } // end of main()