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

You don't have operator overloading defined.
You just initialized it with some concept and left it alone.

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);

Write code for these operator overloading functions.

600) 1(_)[|<.

thanks for the idea...but it's not helping
i don't think the error has much to do with defining the operator...i'm not trying to add or subtract anything, just inputing float type numbers into my matrix.

cin>>elem(i,j); //this is the bit the compiler seems to give the error for

The elem() function call is unncessary there, you can directly access the data member variable, i.e.
cin >> data[the index here].

If you want to stick to using the elem() function call there, you have to change

float elem(int i, int j)

to

float [B]&[/B] elem(int i, int j)

thanks a lot....yes it worked perfecly

sth else that i had problem with was the "+" operator....
this is the + operator overloading definition:

fmatrix operator + (fmatrix& a, fmatrix &b)
{
    int rows,cols,i,j;
    fmatrix add(b); [COLOR="green"]//I gues it's this section i can't figure out (if i dont put 'b' or 'a' in brackets for 'add', it gives erroe and when i put them there, it prints the b or a matrix[/COLOR]     for ( i=0; i<rows; i++)
        for ( j=0; j<cols; j++)
           add.elem(i,j)=(a.elem(i,j)+b.elem(i,j));

    return add;
}

and this is how i've recalled it in the main function:

....
fmatrix a(3,4);
fmatrix b(3,4);
fmatrix c(4,3);
fmatrix p(3,4);
.....

p=a+b;
p.print();

.
.
.

i don't know why it only print the b matrix again...is it because of the definition of the operator?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.