#include<iostream>
using namespace std;
class Array
{
public:
Array()//无参构造函数
{
this->len = 0;
this->space = NULL;
cout<<"Array()"<<endl;
}
Array(int len)//有参构造函数
{
if(len<=0)
{
this->len = 0;
this->space = NULL;
}
else
{
this->len = len;
this->space = new int[len];
cout<<"创建了一个长度为"<<len<<"的数组"<<endl;
}
}
Array(const Array &another)//拷贝构造函数,把另一个数组拷贝过来
{
if(another.len>=0)
{
this->len = another.len;
//执行深拷贝
//先给新对象在堆中创建一定长度的数组
this->space = new int[this->len];
//把原对象的值赋给新对象
for(int i =0;i<this->len;i++)
{
this->space[i] = another.space[i];
}
cout<<"调用了默认拷贝构造函数"<<endl;
}
}
~Array()//析构函数
{
if(this->space != NULL)
{
delete[] this->space;//要先释放this->space指向的空间
this->space = NULL;//再干掉space这个指针
len = 0;
}
cout<<"~Array()"<&l