I'm trying to overload the operator=. I can compile it but whenever I run the program, if I've only A1=A2 is's ok but when I've A1=A2=A3 I get the next fail message:
"This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. terminate called after throwing an instance of 'std::bad_array_new_length' what(): std::bad_array_new_length".
I'm attaching my .cpp file. I'm new here so if there is anything else that you want me to send just let me know.
My .cpp file(including the copy constructor):
#include <cmath>
#include "Array.h"
myArray::myArray()
{
size = 0;
data = new double[size];
for (int i = 0; i < size; i++)
{
data[i] = i;
}
}
myArray::myArray(const myArray& orig) {
setSize(orig.getSize());
data = new double [getSize()];
for (int i = 0; i < getSize(); i++) {
setData(i, orig.getData(i));
}
}
myArray myArray::operator=(const myArray& rhs)
{
delete [] data;
setSize(rhs.getSize());
data = new double [getSize()];
for (int i = 0; i < size; i++)
{
setData(i,rhs.getData(i));
}
}