+ 2
Template and operator overloading
We need to apply templates to XoGrid class used in HW3, so that the user can specify the number of rows, columns and the type of matrix element at compile time. In addition, you need to overload the binary operator â+â inside class XoGrid so that we can create a new object of type XoGrid. The number of rows and the number of columns of that object is the sum of the respective values in the objects that are operands to â+â. For example, if obj1 has a matrix of (3x2) elements and obj2 has a matrix of (4x6) then, calling XoGrid obj3 = obj1 + obj2; will result in obj3 with the dimensions (7x8) Call function print on obj3 to verify that your overloaded operator works properly. How can I do that by using C++ïżŒ
3 Answers
+ 1
It would be helpful to know how you are supposed to add the matrices to produce a final matrix. Usually you cannot add matrices with different dimensions. Could you add an example of adding a (3x2) matrix with a (4x6) matrix? I attached a starting code to your question; it reads in the dimensions of first and second matrix and prints them out.
https://code.sololearn.com/chCyU26kdAKd/#cpp
0
thank you
0
thank you sir