析构函数的调用
各位大侠,小弟编写了一个关于析构函数调用的程序:其中有些不明白之处,望各位大侠指点一二:#include <iostream>
using namespace std;
class date
{
private:
int year;
int month;
int day;
public:
date(int y=2009,int m=1,int d=1);
date(const date& de);
~date();
void showdate();
};
date::date(int y,int m,int d)
{
year=y;
month=m;
day=d;
cout<<"Constructing..."<<endl;
}
date::date(const date &de)
{
year=de.year;
month=de.month;
day=de.day;
cout<<"Copy constructing..."<<endl;
}
date::~date()
{
cout<<"destructing.."<<endl;
}
void date::showdate()
{
cout<<year<<"."<<month<<"."<<day<<endl;
}
date fun(date de1)
{
date date3(de1);
return date3;
}
int main()
{
date obj1(1993,3,20);
date obj3;
date obj2(obj1);
date obj4=obj2;
obj3=obj2;
obj3=fun(obj2);
obj3.showdate();
return 0;
}
输出结果为: 小弟不明白的是:画红线的部分,在那个地方析构函数怎么会被调用,而且还被调用了三次?