How can I sum two complex matrices in C++?

  add, c++, matrix, oop, sum

I am new to C++ oop. I have a class called Matrix which has matrix objects whose elements are complex (from a class that is called complex). However, I get "lvalue required as left operand of assignment" when I try to sum the elements. I have a method that can add complex numbers, so A[i][j] + B[i][j] shouldn’t be a problem. I think I have to overload the " = " operator, but I don’t know how to do it, any advice?

inline Matrix& operator+(Matrix &A, Matrix &B)
{

    Matrix *C = new Matrix;
    for (int i = 0; i < A.rows; i++)
        for (int j = 0; j < A.columns; j++)
            C[i][j] = A[i][j] + B[i][j];

}

Edit:

    complex const* operator[](int const y) const
    {
      return &Matrix[0][y];
    }
    
    complex* operator[](int y)
    {
      return &Matrix[0][y];
    }
}

Source: Windows Questions C++

LEAVE A COMMENT