matrix class
class matrix { public: matrix(int d); matrix(int d1, int d2); ~matrix(); int ub1() const { return (s1 - 1); } int ub2() const { return (s2 - 1); } private: int** p; int s1, s2; }; matrix::matrix(int d): s1(d), s2(d) { if (d < 1) { cerr << "illegal matrix size" << d << "by" << d << "\n"; exit(1); } p = new int*[s1]; for (int i = 0; i < s1; i++) p[i] = new int[s2]; }
matrix::matrix(int d1, int d2): s1(d1), s2(d2) { if (d1 < 1 || d2 < 1) { cerr << "illegal matrix size" << d1 << "by" << d2 << "\n"; exit(1); } p = new int*[s1]; for (int i = 0; i < s1; i++) p[i] = new int[s2]; } matrix::~matrix(){ for (int i = 0; i <= ub1(); ++i) delete p[i]; delete []p; }