FORESTAPE
学海舟舟_林
2017-11-05 06:00

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

5
  • c++

图片说明#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;
}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答