day5.am--拷贝构造与拷贝赋值
1 Array& operator = Array(Array const& that){ 3 //避免自赋值 4 if(&that != this){ 5 //释放旧资源 6 if(m_array) 7 { 8 delete[] m_array; 9 m_array = NULL; 10 } 11 //分配新资源 12 m_array = new int[that.m_size]; 13 //拷贝新内容 14 memcpy(m_array, that.m_array, that.m_size * sizeof(that.m_array[0])); 15 m_size = that.m_size; 16 } 17 //返回自引用 18 return *this; 19 }