Template and operator overloading | Sololearn: Learn to code for FREE!


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++


7/22/2020 11:43:48 AM

Aya Dmaidi

3 Answers

New Answer


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


thank you


thank you sir