I am writing a Qt application for matrix arithmetic . I taken input of 2 3x3 arrays in x1 and y1
if int
is selected and in x2 and y2
if float
is selected . Have a look at MainWindow.cpp .
MainWindow.cpp
int x1[3][3],y1[3][3];
float x2[3][3],y2[3][3];
matrix<int> m1 ;
matrix<float> m2 ;
void MainWindow::addcheck(){
typecheck();
if(ui->intradio->isChecked()){
int** add1 = m1.add(x1,y1);
putresult1(add1);
}
else if(ui->floatradio->isChecked()){
int** add2 = m2.add(x2,y2);
putresult2(add2);
}
}
I am passing these 2 arrays in add function of the matrix class as shown below .
matrix.h
template <class T>
class matrix
{
public:
matrix();
T** subtract(T**&,T**&);
T** add(T**&,T**&);
T** multiply(T**&,T**&);
};
matrix.cpp
template <class T>
T** matrix<T>::add(T**& a, T**& b) {
T c[3][3] ;
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
c[i][j] = a[i][j] + b[i][j] ;
}
}
return c ;
}
However, Im recieving the following error while returning the 2d array to ** . Im unable to decrypt the error . Error:
/Users/sarthakmunshi/prac/mainwindow.cpp:74: error: non-const lvalue reference to type 'int **' cannot bind to a value of unrelated type 'int [3][3]'
add1 = m1.add(x1,y1);
^~
/Users/sarthakmunshi/prac/matrix.h:10: passing argument to parameter here
T** add(const T**&,const T**&);
^