#include <iostream>
using namespace std;
class Date;
class Time{
public:
Time(int h,int m,int s):hour(h),minute(m),sec(s){};
friend void display(const Date &,const Time &);
private:
int hour;
int minute;
int sec;
};
class Date{
public:
Date(int y,int m,int d):year(y),month(m),day(d){};
friend void display(const Date &,const Time &);
private:
int year;
int month;
int day;
};
void display(const Date &d,const Time &t){//友元函数
cout << d.year << "/" << d.month << "/" << d.day << endl;
cout << t.hour << ":" << t.minute << ":" << t.sec << endl;
}
int main(){
Time time(10,13,56);
Date date(2021,3,24);
display(date,time);
return 0;
}
运行结果: