Name: Anonymous 2009-12-02 9:52
I want to:
Numerous pages on google yell that it can be done that way:
but when I try to assign anything it yields that I haven't defined assignment operator:
As far as I understand this code passes a reference to the final M->M[x][y] item or something, then wtf?
Ah whatever, the point is how can I fix it so it'll support all operators on M[x][y] without declaring
them manually? Some suggest to use () overloading but other people flame that idea to death. For me it
looks ugly and non-intuitive.
matrix * M = new matrix ( 4, 3 );
M [ 0 ] [ 2 ] = ( type ) 3;Numerous pages on google yell that it can be done that way:
typedef double type;
class matrix {
private:
int m; // row count
int n; // col count
type * * M; // data
class row {
friend class matrix;
matrix & _a;
int _i;
public:
row ( matrix & a, int i ) : _a ( a ), _i ( i ) { }
type & operator [ ] ( int j ) { return _a . M [ _i ] [ j ]; } };
public:
row operator [ ] ( int i ) { return row ( * this, i ); }
// other stuffbut when I try to assign anything it yields that I haven't defined assignment operator:
327 F:\prj5.cpp no match for 'operator=' in 'M->matrix::operator[](2) = 3.0e+0'As far as I understand this code passes a reference to the final M->M[x][y] item or something, then wtf?
Ah whatever, the point is how can I fix it so it'll support all operators on M[x][y] without declaring
them manually? Some suggest to use () overloading but other people flame that idea to death. For me it
looks ugly and non-intuitive.