Hey guys. I have been working on an assignment where I have to add three objects of a class Matrix. The class should have the flexibility to add more than two oprands without changing any operand on Left hand side of the '=' operator.
the problem is that it is just adding only 2 operands. How can I add more?
It only needs to add 2 operands. However, the prototype should be: Matrix Matrix::operator+(const Matrix& obj) const, so that it may be used with temporary objects (as well as accurately portray what you want to do with the original objects: which is to not modify them.)
obj1 = obj2 + obj3 + obj4; is parsed as: obj 1 = (obj2 + obj3) + obj4;
The first addition produces a temporary Matrix object which is added to obj4 in the second invocation of operator+.