The compiler shows error while overloading << and >> operator, can someone help me removing the error please...thanks.
#include "Matrix.h"
#include <iostream>
using namespace std;
Matrix::Matrix(int m, int n)
{
init(m,n);
}
//destructor to delete the used dynamic memory.
void Matrix::init(int m, int n)
{
rows=m;
cols=n;
data= new double[m*n];
for(int i=0; i<m*n; i++)
data[i]=0;
}
int Matrix::getRow()
{
return rows;
}
int Matrix::getCol()
{
return cols;
}
double& Matrix::operator ()(int r, int c)
{
if (r <0 || r> rows)
{
cout<<"Illegal row index";
return data[0];
}
else if (c <0 || c > cols)
{
cout<<"Illegal Column Index:";
return data[0];
}
else return data[r*cols+c];
}
in>>k(i,j)>>" ";
You can't extract into a string literal. Just remove the underlined lines.
There are several other syntax errors. If you can't fix them then post your updated code. PLEASE USE CODE TAGS. Highlight the code and click the <> button to the right of the edit window.