对类内的枚举类型 记得初始化!!!!
//
// Created by Christina Xinny on 2020/11/25.
//
#include <iostream>
#include <string>
using namespace std;
//1) 定义学生类包含姓名和成绩两个数据成员,重载比较运算符(按成绩和按姓名两个模式比较)和输出运算符。
class Student {
public:
enum SortType {
BY_NAME, BY_SCORE
};
static SortType sort_type;
Student(string name, int score) : name_(name), score_(score) {
}
bool operator>(const Student &rhs) {
if (sort_type == BY_NAME) {
return this->name_ > rhs.name_;
}
else {
return this->score_ > rhs.score_;
}
}
bool operator<(const Student &rhs) {
//to do list
if (sort_type == BY_NAME) {
return this->name_ < rhs.name_;
}
else {
return this->score_ < rhs.score_;
}
}
friend ostream &operator<<(ostream &os, Student &student);
private:
string name_;
int score_;
};
ostream &operator<<(ostream &os, Student &student) {
os << "student's name is " << student.name_ << ",and student's score is " << student.score_ << endl;
return os;
};
template<typename T>
void mySwap(T &a, T &b) {