I have a simple operator + overload method for a class Macierz which is supposed to get the 2d matrix variable from the object, and sum all of this matrix variable with the same field of another Macierz object.
Macierz & operator + (Macierz &f) {
Macierz newM;
for (int i = 0; i < length; i++)
for (int j = 0; j < length; j++)
newM.macierz[i][j] = macierz[i][j] + f.macierz[i][j];
return newM;
}
The calculating works fine. Displaying the newM
variable produces a correct value, however when I try to use it like this:
float y[3][3] = { {1.00f, 2.00f, 3.00f}, { 4.00f, 5.00f, 6.00f }, { 7.00f, 8.00f, 9.00f } };
Macierz m5(y); //fill m5 array with values from above
Macierz m2(2.00f); //fill m2 entirely with 2.00f values
cout << m2 + m5;
The result is an array of zeroes.
How could this happen? The macierz
variable is a simple float[3][3]
field.
Any help would be amazing