hey evryone;
I've created a matrix class (called fmatrix), and im facin a problem with one of the functions: read()......i cannot fill the matrix through keyboard as an input device and keep getting this error:
error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'float'
here's what my prog. looks like:
(including all the headers and all)
//**************************************************************************************
class fmatrix
{
protected:
float *data; // apointer to the memory space the matrix allocates
int rows,cols,size;
//unsigned **p;
public:
fmatrix (int,int);
fmatrix(fmatrix& m);
int rowsize () { return rows; }
int colsize () { return cols; }
~fmatrix()
{delete[] data;}
void read();
unsigned getsize() const //returns the value in protected data member "size"
{return size;}
void store (double x, unsigned index) //stores the value passed by parametre "x" at the
{data[index]=x;} //element number specified by the parametre "index"
double recall (unsigned index)
{return data[index];}
float& operator()(int,int);
float elem(int i, int j)
{ return data[i*cols + j]; }
fmatrix& operator << (fmatrix& m1);
friend fmatrix operator + (fmatrix m1, fmatrix m2);
friend fmatrix operator -(fmatrix m1, fmatrix m2);
friend istream& operator <<(istream& Istr, fmatrix& m);
void print();
};
fmatrix::fmatrix (int rowsz, int colsz)
{
//cout << "constructing matrix object" << endl;
if (rowsz <=0 || colsz <=0)
{ data = 0; return; }
rows = rowsz;
cols = colsz;
data = new float[rows*cols];
}
fmatrix::fmatrix (fmatrix& a)
{
//cout << "copying matrix object" << endl;
rows = a.rows;
cols = a.cols;
int size = rows*cols;
data = new float[size];
for (int i=0 ; i<size ; i++)
data[i] = a.data[i];
}
void fmatrix::read()
{
for (int i=0; i<rows; i++)
{
cout<<"Enter the values for line "<<i+1<<"Of matrix: "<<endl;
for (int j=0; j<cols-1; j++)
cin>>elem(i,j); //[B]this is the bit the compiler seems to give the error for [/B]
}
}
void fmatrix::print()
{
for (int i=0; i<rows; i++)
{
for (int j=0; j<cols-1; j++)
cout << elem(i,j) << " | ";
cout << elem(i,cols-1) <<endl;
}
}
float& fmatrix::operator() (int i, int j)
{
if (i<0 || i>= rows)
cout<<"class matrix: column index out of range";
if (j<0 || j>= cols)
cout<<"class matrix: row index out of range";
return data[i*cols + j];
}
//*****************************************************************************************
main()
{
int i,j;
fmatrix a(3,5);
fmatrix c(5,3);
//for ( i=0; i<3; i++)
//{cout<<"Enter value for line "<<i+1<<"of matrix a:"<<endl;
//for(int j=0; j<5; j++)
// cin >> a(i,j);
//}
a.read();
cout << "Elements of A:" << endl;
a.print();
return 0;
}
i'd be more than happy for any clue....i'm desperately in need of help