标签:
#include <iostream>
using namespace std;
class Test1
{
public:
Test1()
{
//赋值
//p=NULL;
// or p=new int;
}
//重要
Test1& operator=(const Test1& test1)
{
if(&test1!=this)
{
cout << "赋值操作符" << endl;
}
return *this;
}
~Test1()
{
cout<<"Test1 destructor"<<endl;
if(p!=NULL)
delete p;
}
private:
int *p;
};
class Test2
{
public:
Test2(const Test1& test1)
{
a=test1;
}
~Test2()
{
cout<<"Test2 destructor"<<endl;
}
private:
//Test a;
Test1 a;
};
int main()
{
Test1 test1;
Test2 *c=new Test2(test1);
delete c;
//system("pause");
return 0;
}
标签:
原文地址:http://blog.csdn.net/greenapple_shan/article/details/45458635