#include #include "matrix.h" using namespace std; /* TO TEST: ok matrix(int rows = 0, int cols = 0); ok ~matrix() { delete[] element; } ok int rowss() const { return rows; } ok int columns() const { return cols; } ok int times(int i, int j, matrix& left, matrix& right) const;//If unused, write it in private T& operator()(int i, int j) const; matrix& operator=(const matrix& x); //matrix operator+() const; matrix operator+(const matrix& x) const; //matrix operator-() const; matrix operator-(const matrix& x) const; matrix operator*(const matrix& x) const; matrix& operator+=(const matrix& x); friend ostream& operator<<(const matrix& x); */ int main() { int l[] = { 1,2,3,4,5,6 }; matrix left(2, 3, l), right(3, 2, l); cout << "left: " << endl << left << endl; cout << "right: " << endl << right << endl; cout << "left(1, 1): " << left(1, 1) << endl; cout << "right(2, 1): " << right(2, 1) << endl << endl; int out[] = { 1,2,3,4 }; matrix tmp(2, 2, out); tmp = left * right; cout << "times: " << endl << tmp << endl << endl; //还是有地方浅拷贝了,调试过程中最好加上引用 //大概率是拷贝构造函数的问题,如果直接输出非引用,会创建新的对象,这个对象会出问题,比如double delete之类 cout << "transpose: " << endl << tmp.transpose() << endl; cout << "transpose left: " << endl << left.transpose() << endl; cout << "transpose right: " << endl << right.transpose() << endl; return 0; } /* left: 1 2 3 4 5 6 right: 1 2 3 4 5 6 left(1, 1): 1 right(2, 1): 3 times: 22 28 49 64 transpose: 22 49 28 64 transpose left: 1 4 2 5 3 6 transpose right: 1 3 5 2 4 6 */