友元-----练习
#include<iostream>
using namespace std;
class Data;
class Time
{
public:
Time(int,int,int);
void display(Data &d);
private:
int hour;
int min;
int secede;
};
class Data
{
public:
friend void Time::display(Data &d);
Data(int,int,int);
private:
int year;
int month;
int day;
};
void Time::display(Data &d)
{
cout<<d.year<<"/"<<d.month<<"/"<<d.day<<endl;
cout<<hour<<":"<<min<<":"<<secede<<endl;
}
Time::Time(int h,int m,int s):hour(h),min(m),secede(s){}
Data::Data(int y,int m,int d):year(y),month(m),day(d){}
int main()
{
Time t(12,0,0);
Data d(2013,8,8);
t.display(d);
return 0;
}