Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

2d matrices [ ] [ ] overloading

Name: Anonymous 2009-12-02 9:52

I want to:
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 stuff

but 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.

Name: Anonymous 2009-12-02 10:10

Look at someone else's matrix class.

Name: Anonymous 2009-12-02 10:30

As a SEASONED ENTERPRISE PROGRAMMER myself I would be more familiar with the following syntax

Matrix<TDouble>* myMatrixPtr = MatrixFactory<TDouble>::Manufacture(TInteger(4), TInteger(3));

myMatrixPtr->getRowPtr(TInteger(0))->getColumnPtr(TInteger(2))->assignNewValue(TDouble(3));

Name: Anonymous 2009-12-02 10:34

found the culprit...

( * M ) [ 0 ] [ 2 ] instead of M [ 0 ] [ 2 ]

JESUS

Name: Anonymous 2009-12-02 10:51

Programming by permutation?

Name: Anonymous 2009-12-02 12:18

>>3
MatrixFactory?

Name: Anonymous 2013-06-18 18:26

Name: Anonymous 2013-06-18 18:33

Name: Anonymous 2013-06-18 18:40

Name: Anonymous 2013-06-18 18:47

Name: Anonymous 2013-06-18 18:54

Name: Anonymous 2013-06-18 19:00

Name: Anonymous 2013-06-18 19:07


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List