C++符号重载问题,为什么p1.output()打印不出来,p2没有赋给p1吗,怎么改。。。

图片说明#include
using namespace std;

class People{
public:
bool operator ==(const People &b){
if(this->id==b.id){
cout<<"两个people对象的id相同"<<endl;
return true;
}

    else{
        cout<<"两个people对象的id不同"<<endl;
        return false;
    }

}
void operator =(const People &b){
*this=b;
}
input();
output(){
cout<<"输出人员信息:"<<endl;
cout<<"编号:"<<number<<endl<<"性别:"<<sex<<endl;
cout<<"出生日期:"<<birthday<<endl<<"身份证号:"<<id<<endl<<endl;
}

private:
double number;
char sex[10];
char birthday[20];
double id;
};
People::input(){
cout<<"录入people信息"< cout cin>>number;

    cout<<"性别:";
    cin>>sex;

    cout<<"出生日期:";
    cin>>birthday;

    cout<<"身份证号:";
    cin>>id;
    cout<<endl;

}

int main(int argc,char *argv[]){
People p1,p2;
p1.input();
p2.input();
p1.operator ==(p2);
p1.operator =(p2);
cout<<"将p2赋给p1:"<<endl;
p1.output();
system("pause");
return 0;
}

您好
楼主您的程序中对于复制号=的重载有问题,导致程序在执行p1.operator =(p2);时崩溃
因此并不是p1.output();打印不出来的问题,而是在那之前程序就被系统kill掉了。
关于赋值号=的重载,还请您务必对各个私有成员分别采取对应赋值操作,将您的对赋值号的重载部分修改如下:

        void operator =(const People &b) {
            //*this=b;
            this->number = b.number;
            this->id = b.id;
            strcpy(this->sex, b.sex);
            strcpy(this->birthday, b.birthday);
        }

运行情况如下:
修改后的运行情况
请您自行增加对于头文件<cstring><string.h>的引用。
若对您有帮助,请您采纳,谢谢!

你void operator =(const People &b){
*this=b;
}这个函数错了!
你这样写堆栈溢出了到这里会崩的,所以后面的语句不会执行。
赋值操作符重载 你可以改成这样}
People& operator =(const People &b)
{
this->id = b.id;
number = b.number;
//等等其他成员变量赋值
return *this;

}

还有构造函数,析构函数虽然编译器会自动帮你添加但还是要自己写出来比较好。还有你贴出的input();函数那些是没返回值的也不对

类对象之间的赋值,哪有一个等号那么简单。要注意!默认情况下,p1=p2,是指p2这个对象的指针(引用)赋给p1,而不是创建p2的副本,此时p1,p2都指向同一块内存,对p1进行操作等同于对p2操作。如果重载运算符“=”,实现复制功能,那就要把所有的属性都一一复制,而不是*this=b就了事。
给个例子

 void operator =(const People &b)
 {
    this.number=b.number;
        this.id=b.id;
        .......
}