#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) { x=t.x+9; cout<<"copy construct: "<<x<<endl;}
};
int main()
{
T t1(100);
T t2(t1);
return 0;
}
this关键字
T t1(100), t2(t1); T t2(t1); T t1(100), t2(t1);
#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);
T t2(t1);
return 0;
}
#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);
return 0;
}