袁辉勇 4=25-4 连续调用拷贝构造函数
#include <iostream>
using namespace std;
class T
{
int x;
public:
T (int xx){x=xx; cout<<"construct: "<<x<<endl;}
//(十二)
~T () {cout<<"destruct: "<<x<<endl;}
T(T &t) { this ->x=t.x+9; cout<<"copy construct: "<<x<<endl;}
};
int main()
{
T t1(100), t2(t1), t3(t2);
cout<<"*************\n";
return 0;
}
T t1(100), t2(t1), t3=t2;
#include <iostream>
using namespace std;
class T
{
int x;
public:
T (int xx){x=xx; cout<<"construct: "<<x<<endl;}
//(十3)
~T () {cout<<"destruct: "<<x<<endl;}
T(T &t) { this ->x=t.x+9; cout<<"copy construct: "<<x<<endl;}
};
int main()
{
T t1(100), t2(t1), t3=t2;
cout<<"*************\n";
return 0;
}
C++ 文章被收录于专栏
C++谭浩强 冯博强 贾应知 袁辉勇