[求助]关于类嵌套
#include<iostream>using namespace std;
class date
{
public:
date();
date(date &d);
void setdate();
void showdate();
private:
int year,month,day;
};
date::date(){
year=0;
month=0;
day=0;
}
date::date(date & d){
year=d.year;
month=d.month;
day=d.day;
}
void date::setdate(){
cout<<"依次输入年,月,日"<<endl;
cin>>year;
cin>>month;
cin>>day;
}
void date::showdate(){
cout<<year<<"-"<<month<<"-"<<day<<endl;
}
class personnel
{
public:
personnel();
personnel(personnel & p);
void setdata_per();
void showdata_per();
private:
int name;
int number;
char sex;
date birthday;
int numofindentity;
};
personnel::personnel(){
name=0;
number=0;
sex=0;
numofindentity=0;
}
personnel::personnel(personnel &p){
birthday=p.birthday;
number=p.number;
sex=p.sex;
numofindentity=p.numofindentity;
}
void personnel::setdata_per(){
cout<<"input name"<<endl;
cin>>name;
cout<<"input number"<<endl;
cin>>number;
cout<<"input sex"<<endl;
cin>>sex;
cout<<"input birthday"<<endl;
birthday.setdate();
cout<<"input number of indentity"<<endl;
cin>>numofindentity;
}
void personnel::showdata_per(){
cout<<name<<" ";
cout<<number<<" ";
cout<<sex<<" ";
birthday.showdate();
cout<<" ";
cout<<numofindentity<<" "<<endl;
}
int main(){
personnel person1;
person1.setdata_per();
person1.showdata_per();
cout<<endl;
personnel person2(person1);
person2.showdata_per();
return 0;
}
创建完person1之后,执行setdata_per()函数,但是在输入完姓名的之后,setdata_per()中后面的语句都没有执行,这是什么问题啊?
如果觉得我讲得不清楚,请大家编译一下就知道了,麻烦了.