1 题目实例
class Date
{
public:
Date(int year, int minute, int day)
{
cout << "Date(int,int,int):" << this << endl;
}
Date(const Date& d)
{
cout << "Date(const Date& d):" << this << endl;
}
~Date()
{
cout << "~Date():" << this << endl;
}
private:
int _year;
int _month;
int _day;
};
Date Test(Date d)
{
Date temp(d);
return temp;
}
int main()
{
Date d1(2022, 1, 13);
Test(d1);
return 0;
}
2 结果分析
Date(int,int,int):00D3FE6C
Date(const Date& d):00D3FD5C
Date(const Date& d):00D3FD30
Date(const Date& d):00D3FD8C
~Date():00D3FD30
~Date():00D3FD5C
~Date():00D3FD8C
~Date():00D3FE6C
执行过程
-
创建对象
d1
: