首页 > 技术文章 > C++ 运算符重载

ShineLeBlog 2020-03-25 16:51 原文

class P{
    public:
    int id;
    char name[10];
    int age;
    P() {
        this->id = 0;
        for (int i = 0; i < 10; i++)
            this->name[i] = '\0';
        this->age = 0;
    }
    void operator = (P p){
        int i=0;
        this->id=p.id;
        for(i=0;*(p.name+i)!='\0';i++) 
            this->name[i]=p.name[i];
        this->name[i]='\0';//这里字符串结尾必须加'\0',否则会经常出错
        this->age=p.age;
    }
};

 

推荐阅读