请教以下关于C++代码的问题

[复制链接]
查看11 | 回复1 | 2008-8-31 19:59:57 | 显示全部楼层 |阅读模式
编译不通过
代码如下
#include
using namespace std;
class time
{
public:
time(int,int,int);
void display(date&);
private:
int hour;
int minute;
int sec;
};
class date
{
public:
date(int,int,int);
friend void time::display(date&);
private:
int month;
int day;
int year;
};
time::time(int h,int m,int s)
{
hour=h;
minute=m;
sec=s;
}
date::date(int m,int d,int y)
{
month=m;
day=d;
year=y;
}
void time::display(date&d)
{
cout<<d.month<<"/"<<d.day<<"/"<<d.year<<endl;
cout<<hour<<":"<<minute<<":"<<sec<<endl;
}
int main()
{
time t1(10,13,56);
date d1(12,25,2004);
t1.display(d1);
return 0;
}
请高手帮忙指正 谢谢~

回复

使用道具 举报

千问 | 2008-8-31 19:59:57 | 显示全部楼层
//需要更改time类的名,因为标准中有time的成员或函数;//我吧time改为了Time#include using namespace std; class date;//要先声明Date类,因为Time类的display函数中使用了date &;class Time { public: Time(int,int,int); void display(date&); private: int hour; int minute; int sec; }; class date { public: date(int,int,int); friend...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行