I have simple class which holds array of integers. I want to overload + to merge two ararys together. I have defined two overloadors. + and =
class Money{
Money & operator =( const Money &a )
{
for( int i = 0; i < size ;i++ ) arr[i] = a.arr[i];
return *this;
}
Money & operator +( const Mone &a )
{
Money temp;
for( int i = 0; i < size ;i++ ){
temp.arr[i] = arr[i] + a.arr[i];
}
return temp;
}
private:
int arr[50];
int size = 50;
}
The problem is index 0, it returns random number from memory . I have seen some question about similliar problem but with * operator ( i will try to find it and link it ), where i got my operator = from. What is causing this? I am invoking it as
Money a;
Money b;
Money d;
d = a + b;
// print array;
I am new to overloading so i have harder time analyzing and understaning concept.