#include #include "Matrix.h" using namespace std; const int SIZE = 5; // const so can't change value later int main() { // Create int Matrix objects a and b Matrix a(SIZE, SIZE); Matrix b(SIZE, SIZE); for (int i = 0; i < SIZE; i++) { a.at(i,i) = 1; b.at(i, (i+1) % SIZE) = 1; } cout << endl << "Matrix a:" << endl; cout << a; cout << endl << "Matrix b:" << endl; cout << b; // Compilers do strange things. Compare this line with // the equivalent implementation below (look at which // functions are called) Matrix c = a.add(b); // Matrix c; // c = a.add(b); cout << endl << "Matrix c is the sum of a and b:" << endl; cout << c; Matrix d = c; // Uses the copy constructor // "Extract" a C-style array from the Matrix object a int aRows, aCols; int **aArray = a.cArray(&aRows, &aCols); // Note &, "address of" cout << endl << "a as a C array:" << endl; for (int i = 0; i < aRows; i++) { for (int j = 0; j < aCols; j++) { cout << aArray[i][j] << "\t"; } cout << endl; } delete [] aArray[0]; // deletes data array (Why??) delete [] aArray; // deletes row ptr array return 0; }