【无标题】来华清的第好几天

#include 

 


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 
  
        {
            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="< 
  
         cout<<"age2="< 
  
    }
};
int main(int argc, char *argv[])
{
    bool compare;
    stu a(1,1);
    stu b(1,1);
    if((b==a))
    {
        cout<<"true"< 
  
    }
    else
    {
        cout<<"false"< 
  
    }
 
  
 
  
    return 0;
}
 
 

你可能感兴趣的:(c++,java,开发语言)