拷贝函数

//复制构造函数也是构造函数

#include<iostream>

using namespace std;
class Date{
private :
    int year,month,day;
public :
    Date(int y=2009,int m=1,int d=1);
    Date(const Date &date);//????????
    ~Date()
    {
        cout<<"destructing..."<<endl;
    };
    void ShowDate();
};
Date::Date(int y, int m, int d)//???????
{
    year=y;
    month=m;
    day=d;
    cout<<"constructing..."<<endl;
};
Date::Date(const Date& date1)//???????
{
   year=date1.year;
   month=date1.month;
   day=date1.day;
   cout<<"Copy Constructing..."<<endl;
};
void Date::ShowDate()
{
    cout<<year<<"."<<month<<"."<<day<<endl;
};
Date Fun(Date date2)//???????????
{
    Date date3(date2);//?????????????
    return date3;
}
int main()
{
    Date obj1(1999,3,20);
    Date obj3;
    Date obj2(obj1);

    Date obj4=obj2;//??????????????Date day4(day2)

    Date obj5();//其实是调用拷贝函数

    obj3=obj2;
    obj3=Fun(obj2);
    obj3.ShowDate();
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值