when dealing with object copy and dynamic memory allocation it's a good idea to use a swap helper function
A(const A& other)
: myArray(0)
, _size(0)
{
if(this != &other) {
A my_tmp_a(other._size);
std::copy(&other[0], &other[other._size], &my_tmp_a[0]);
swap(my_tmp_a);
}
}
const A& operator=(const A& other)
{
if(this == &other) return *this;
A my_tmp_a(other._size);
std::copy(&other[0], &other[other._size], &my_tmp_a[0]);
swap(my_tmp_a);
return *this;
}
void swap(const A& other) {
int* my_tmp_array = this.myArray;
this.myArray = other.myArray;
other.myArray = my_tmp_array;
int my_tmp_size = this._size;
this._size = other._size;
other._size = my_tmp_size;
}