#include<iostream>
using namespace std;
//将例9-13程序中Time声明为Date的友元类
class Date;
class Time
{
public:
Time(int h,int m,int s):hour(h),minute(m),sec(s){}
void display(Date&);
private:
int hour;
int minute;
int sec;
};
class Date
{
public:
Date(int y,int mo,int d):year(y),month(mo),day(d){}
friend Time; //将time声明为date的友元类
private:
int year;
int month;
int day;
};
void Time::display(Date& d1)
{
cout << d1.year << "/" << d1.month << "/"<< d1.day << endl;
cout << hour << "/" << minute << "/" << sec << endl;
}
int main()
{
Time t(10, 13, 56);
Date d(12, 25, 2004);
t.display(d);
return 0;
}
谭浩强c++第三版9-11
最新推荐文章于 2024-08-03 18:36:56 发布