Addition operator failing

Problem with this Function: Row operator+(const Row &x) const;

OUTPUT:
Addition operator is returning an incorrect value.
Addition operator should be const.

Here is my Row.cpp file
#include "Row.h"

Row :: Row(double *dArr, int s)
{
size = s;
dArray = new double[size];

for(int i=0; i<size; i++)
{
dArray[i] = 0;
}

dArray = dArr;


}


Row :: Row(int s)
{
size = s;

dArray = new double[size];

for(int i=0; i<size; i++)
{
dArray[i] = 0;
}
}

Row :: Row()
{
dArray = new double[0];
}

int Row :: getSize() const
{
return size;
}

double *Row :: getData()
{
double *newRow = new double[size];

for(int i =0; i<size; i++)
{
newRow[i] = dArray[i];
}

return newRow;
}

Row :: ~Row()
{
for(int i=0; i<size; i++)
{
if(dArray[i])
{
delete []dArray;
}

dArray = 0;
size =0;
}
}

Row Row :: operator[](const int i)
{
while(i<size)
{
if(dArray[i])
{
return dArray[i];
}
}
}

Row Row :: operator=(Row &x)
{
double *newDArr = new double[size];

for(int i =0; i<size; i++)
{
newDArr[i] = dArray[i];
}

x.dArray = newDArr;

}

Row Row :: operator*(const unsigned int scalar)
{
Row x(size);
for(int i =0; i<size; i++)
{
x.dArray[i] = dArray[i]*scalar;
}

return x;


}

Row Row :: operator-(const Row &x)
{
Row Sub(size);

for(int i =0; i<size; i++)
{
Sub.dArray[i] = dArray[i] - x.dArray[i];
}

return Sub;
}

Row Row :: operator+(const Row &x) const
{
Row Add(size);

Row same(size);

for(int l = 0; l<size; l++)
{
same.dArray[l] = dArray[l];
}

double val1 = 0.0;
double val2 = 0.0;

for(int i =0; i<size; i++)
{
val1 = same.dArray[i];
val2 = x.dArray[i];
Add.dArray[i] = val1 + val2;
}

for(int y =0; y<size; y++)
{
if(dArray[y] != same.dArray[y])
{
dArray[y] = same.dArray[y];
}
}

return Add;
}

double Row :: operator*(const Row &x)
{

double total = 0;
for(int i=0; i<size; i++)
{
total = total + (dArray[i]*x.dArray[i]);
}

return total;
}

Row Row :: operator++()
{
Row z(size);

for(int i =0; i<size; i++)
{
z.dArray[i] = z.dArray[i]++;
}

return z;
}

Row Row :: operator--()
{
Row z(size);

for(int i =0; i<size; i++)
{
z.dArray[i] = z.dArray[i]--;
}

return z;
}

bool Row :: operator !=(const Row &x){

if(x.dArray != dArray)
{
return true;
}
else
{
return true;
}
}
What is the last loop in operator+ for?
1
2
3
4
5
6
7
for(int y =0; y<size; y++)
{
	if(dArray[y] != same.dArray[y])
	{
		dArray[y] = same.dArray[y];
	}
}

I do not understand why are you listing all this functions? Show the declaration of the operator inside the class.
Topic archived. No new replies allowed.