| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 854 人关注过本帖
标题:[求助]关于类嵌套
只看楼主 加入收藏
a19870502
Rank: 1
等 级:新手上路
帖 子:114
专家分:0
注 册:2007-10-31
结帖率:100%
收藏
 问题点数:0 回复次数:4 
[求助]关于类嵌套
#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()中后面的语句都没有执行,这是什么问题啊?
如果觉得我讲得不清楚,请大家编译一下就知道了,麻烦了.
搜索更多相关主题的帖子: date 嵌套 month year void 
2008-04-22 09:26
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
一, string name;
二,personnel::personnel():birthday(){

    name="0";

    number=0;

    sex=0;

    numofindentity=0;


}

学习需要安静。。海盗要重新来过。。
2008-04-22 09:58
a19870502
Rank: 1
等 级:新手上路
帖 子:114
专家分:0
注 册:2007-10-31
收藏
得分:0 
十分感谢,问题解决了.
但是我不明白为什么会这样?是数据类型的影响吗?
麻烦了.
2008-04-22 14:50
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
名字是字符串的....一般情况用变量之前初始化..而很大部分情况的错误是由于变量的初始化引起的

学习需要安静。。海盗要重新来过。。
2008-04-22 14:52
a19870502
Rank: 1
等 级:新手上路
帖 子:114
专家分:0
注 册:2007-10-31
收藏
得分:0 
再次感谢!
2008-04-22 21:16
快速回复:[求助]关于类嵌套
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012243 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved