#include <iostream>
using namespace std;
class stu
{
private:
int age1;
int age2;
mutable bool compare;
public:
stu()
{}
stu(int age1,int age2):age1(age1),age2(age2)
{}
//类中成员实现大于>运算符的操作
const bool operator>(const stu &other)const
{
if(age1>other.age1&&age2>other.age2)
{
compare=true;
}
else
{
compare=false;
}
return compare;
}
//类中成员实现小于<运算符的操作
const bool operator<(const stu &other)const
{
if(age1<other.age1&&age2<other.age2)
{
compare=true;
}
else
{
compare=false;
}
return compare;
}
//类中成员实现大于>=运算符的操作
const bool operator>=(const stu &other)const
{
if(age1>=other.age1&&age2>=other.age2)
{
compare=true;
}
else
{
compare=false;
}
return compare;
}
//类中成员实现小于等于<=运算符的操作
const bool operator<=(const stu &other)const
{
if(age1<=other.age1&&age2<=other.age2)
{
compare=true;
}
else
{
compare=false;
}
return compare;
}
//类中成员实现等于==运算符的操作
const bool operator==(const stu &other)const
{
if(age1==other.age1&&age2==other.age2)
{
compare=true;
}
else
{
compare=false;
}
return compare;
}
//类中成员实现不等于!=运算符的操作
const bool operator!=(const stu &other)const
{
if(age1!=other.age1&&age2!=other.age2)
{
compare=true;
}
else
{
compare=false;
}
return compare;
}
void fun()
{
cout<<"age1="<<age1<<endl;
cout<<"age2="<<age2<<endl;
}
};
int main(int argc, char *argv[])
{
bool compare;
stu a(1,1);
stu b(1,1);
if((b==a))
{
cout<<"true"<<endl;
}
else
{
cout<<"false"<<endl;
}
return 0;
}