CS 596 OODP
Matrix Class
[To Lecture Notes Index]
San Diego State University -- This page last updated Oct. 10, 1995

#include
class Matrix
{ public :
Matrix(int NumOfRows, int NumOfColumns);
~Matrix();
int* operator[](int whichRow);
private:
int* elements;
int RowSize;
int ColumnSize;
};
Matrix :: Matrix(int NumOfRows, int NumOfColumns) {
elements = new int[ NumOfRows * NumOfColumns];
RowSize = NumOfColumns;
ColumnSize = NumOfRows;
};
int* Matrix :: operator[](int whichRow) {
return elements + ( whichRow * RowSize);
};
Matrix :: ~Matrix() { delete elements;};
void main() {
Matrix Test(10, 20 );
Test[3][5] = 10;
cout << Test[3][5] << endl;
}