| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 424 人关注过本帖
标题:请教一个问题!谢谢!
只看楼主 加入收藏
elan1986
Rank: 6Rank: 6
等 级:贵宾
威 望:18
帖 子:458
专家分:407
注 册:2007-12-17
结帖率:100%
收藏
 问题点数:0 回复次数:1 
请教一个问题!谢谢!
include<iostream>
using namespace std;
class date
{
public:
    date(int year=1900,int month=1,int day=1) {Xyear=year; Xmonth=month; Xday=day;}
    date(date &p);
    int GetYear()  {return Xyear;}
    int Getmonth() {return Xmonth;}
    int Getday()   {return Xday;}
    void showdate();
private:
    int Xyear,Xmonth,Xday;
};

date::date(date &p)
{
    Xyear=p.Xyear;
    Xmonth=p.Xmonth;
    Xday=p.Xday;
}

inline void date::showdate()
{
    cout<<"出生日期:"<<Xyear<<"年"<<Xmonth<<"月"<<Xday<<"日"<<endl;
}

class people
{
public:
    people(int no,char sex,date birthday,int id);
    people(people &);
    ~people();
    void showpeople();

private:
    int No,Id;
    char Sex;
    date Birthday;
};

people::people(int no,char sex,date birthday,int id):Birthday(birthday)
{
    int    No=no;
    char Sex=sex;
    int Id=id;
}

people::people(people &) {}

people::~people() {}

 inline void people::showpeople()
{
    cout<<"编号为:"<<No<<"性别为:"<<Sex<<"出生日期为:"<<Birthday.showdate()<<"身份证为:"<<Id<<endl;
}

void main()
{
    date aa(1986,5,24);
    int no,id;
    char sex;
    people bb(no,sex,aa,id);
    cout<<"请分别输入编号,性别,出生日期和身份证号码:"<<endl;
    cin>>no>>sex>>aa.GetYear()>>aa.Getmonth()>>aa.Getday()>>id;
    cout<<"我的信息是:"<<endl;
    bb.showpeople();
}

我不知道该怎么去修改这几个错误
谢谢了
错误:
--------------------Configuration: lch - Win32 Debug--------------------
Compiling...
a1.cpp
D:\lch\a1.cpp(55) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'void' (or there is no acceptable conversion)
D:\lch\a1.cpp(65) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'int' (or there is no acceptable conversion)
Error executing cl.exe.

lch.exe - 2 error(s), 0 warning(s)
搜索更多相关主题的帖子: private include 出生日期 public return 
2008-10-08 09:39
lonmaor
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:郑州
等 级:版主
威 望:75
帖 子:2637
专家分:6423
注 册:2007-11-27
收藏
得分:0 
cin>>no>>sex>>aa.GetYear()>>aa.Getmonth()>>aa.Getday()>>id;
拿这句来讲,
people类的成员函数GetYear()返回一个int值,只能用于右值(right-value).

showDate()函数的声明是void showdate();
一个无返回值的函数,
而这句:cout<<"编号为:"<<No<<"性别为:"<<Sex<<"出生日期为:"<<Birthday.showdate()<<"身份证为:"<<Id<<endl;
你让它cout一个void值。不可取。

从不知道到知道,到知道自己不知道,成长的道路上脚步深深浅浅
2008-10-08 11:28
快速回复:请教一个问题!谢谢!
数据加载中...
 
   



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

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