友元类

#include<iostream>
using namespace std;
class D{
private:
int year;
int month;
int day;
public :
D(int y,int m,int d)
{
cout<<"Constructing D"<<endl;
year=y;
month=m;
day=d;
}
~D()
{
cout<<"释放D......\n";
}
void Show()
{
cout<<year<<"."<<month<<"."<<day<<endl;
}
};
class Time
{
private:
 int hour;
 int minute;
 int second;
public:
 Time(int h, int m, int s)
 {
cout<<"Constructing Time"<<endl;
hour=h;
minute=m;
second=s;
 }
 ~Time()
 {
 cout<<"释放Time\n";
 }
 void Show()
{
cout<<hour<<":"<<minute<<":"<<second<<endl;
}
};
class Schedule
{
private:
 int number;
 D date;   // 定义对象成员 date
 Time time;  // 定义对象成员 time
public:
 Schedule(int num, int a, int b, int c, int d, int e, int f): date(a,b,c), time(d,e,f)
 {
cout<<"Constructing Schedule"<<endl;
number=num;
 }
 ~Schedule()
 {
cout<<"释放Schedule"<<endl;
 }
 void show()
 {
cout<<"number"<<number<<":";
date.Show();   // 调用对象成员date的show()函数
time.Show();  // 调用对象成员time的 show()函数
 }
};
int main()
{
Schedule obj1(1,2008,3,12,12,10,0);
obj1.show();
Schedule obj2(2,2009,2,8,18,20,0);
obj2.show();
return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值