[] overload for matrix
Marco Schneider
Marco_Schneider@public.uni-hamburg.de
Wed Apr 26 11:44:00 GMT 2000
Hello
I have a question.
I tried to overload the [] operator for a class matrix
I wanted to use it to change the private elements so that it is
possible to write
m[2][3] = 10; for exampel if -m- is a object of the class matrix
This worked fine with array as written in the exampel below
double & operator[](int z); // header
double & array::operator[](int z)
{
return m[z];
}
The problem with matrixes is, that the [] operator accepts only one
Argument
and i found no way to change this. Is this possibel or not ???
Below there is a short part of the program I tried to run.
class matrix
{
private:
unsigned long row;
unsigned long colum;
double * m;
public:
double & operator[](int r,int c);
};
// class funktion
double & matrix::operator[](int c,int r)
{
return m[row * c + r];
}
I would be very happy about any kind of help.
With many thanks in advance.
Marco
More information about the Gcc-help
mailing list