#include <iostream>
#include <string>
using namespace std;
class Student {
public:
Student();
Student(const string& name,int score1,int score2,int score3);
friend ostream& operator<<(ostream& myout,const Student& s);
bool operator > (const Student& s1);
private:
string name;
int score1, score2, score3;
};
template<class A>
A getmax(A a,A b) {
return a > b ? a : b;
}
//主函数
int main() {
Student s1("小王", 60, 70, 80), s2("小徐", 89, 90, 95);
cout << getmax(s1, s2) << endl;
system("pause");
return 0;
}
Student::Student()
{
name = " ";
score1 = 0;
score2 = 0;
score3 = 0;
}
Student::Student(const string& name, int score1, int score2, int score3)
{
this->name = name;
this->score1 = score1;
this->score2 = score2;
this->score3 = score3;
}
bool Student::operator>(const Student& s1)
{
if ((this->score1 + this->score2 + this->score3) > (s1.score1 + s1.score2 + s1.score3)) {
return true;
} return false;
}
ostream& operator<<(ostream& myout, const Student& s)
{
myout << "姓名:" << s.name << "\t成绩1:" << s.score1
<< "\t成绩2:" << s.score2 << "\t成绩3:" << s.score3 << endl;
return myout;
}