12.29

12.29_第1张图片

#include 

using namespace std;
class Person{
    int *age;
    string &name;
public:
    Person(string name):age(new int),name(name){}
    Person(int age,string name):age(new int(age)),name(name){}
    ~Person(){
        delete age;
    }
    Person(const Person &other):age(new int (*(other.age))),name(other.name){}
    Person &operator=(const Person &other){
        this->name=other.name;
        *(this->age)=*(other.age);
        return *this;
    }
    void show(){
        cout<<"age="<<*age<age)+(*other.age);

    return t;
}
Person operator+(Person &c1,Person &c2){
    Person t(0,"zhangsan");
   *(t.age)=*(c1.age)+(*(c2.age));

   return t;
}
Person operator*(Person &c1,Person &c2){
    Person t(0,"zhangsan");
   *(t.age)=*(c1.age)*(*(c2.age));

   return t;
}
Person Person::operator*(Person &other){
    Person t(0,"zhangsan");
    *(t.age)=*(this->age)*(*other.age);

    return t;
}
Person operator-(Person &c1,Person &c2){
    Person t(0,"zhangsan");
  *(t.age)=*(c1.age)-(*(c2.age));

    return t;
}
Person Person::operator-(Person &other){
    Person t(0,"zhangsan");
   *(t.age)=*(this->age)-(*other.age);

    return t;
}
Person operator/(Person &c1,Person &c2){
    Person t(0,"zhangsan");
    *(t.age)=*(c1.age)/(*(c2.age));

    return t;
}
Person Person::operator/(Person &other){
    Person t(0,"zhangsan");
    *(t.age)=*(this->age)/(*other.age);

    return t;
}
Person operator%(Person &c1,Person &c2){
    Person t(0,"zhangsan");
    *(t.age)=*(c1.age)%(*(c2.age));

    return t;
}
Person Person::operator%(Person &other){
    Person t(0,"zhangsan");
    *(t.age)=*(this->age)%(*other.age);

    return t;
}
bool Person::operator==(Person &other){
    if(this->age==other.age){
        if(this->name==other.name){
            return this->name==other.name;
        }
    }
}
bool Person::operator!=(Person &other){
    if(this->age!=other.age){
        return this->age!=other.age;
    }else{
        if(this->name!=other.name){
            return this->name!=other.name;
        }else{
            return this->name!=other.name;
        }
    }
}
bool Person::operator&&(Person &other){
    return (*(this->age)&&*(other.age));
}
void Person::operator()(){
    cout<<"hello"<

12.29_第2张图片

你可能感兴趣的:(作业,程序人生)