i have a template matrix it works and every thing but when its finished it stucks at the destructor here is my header
template <class T> class Matrix { private: string type; int row, col; T **array; void rowShiftDown(const int shiftSize); void colShiftLeft(const int shiftSiz); void Matrix::rowShiftUp(const int shiftSize); void Matrix::colShiftRight(const int shiftSize); public: Matrix(int rows, int cols,string matType); // set the (i,j) element to be 'data' void setElement(int i, int j, T data); // return the (i,j) element T getElement(int i, int j); // add 'this' to 'other' and put the result in 'result' void add(Matrix& other, Matrix& result); // rowShift void rowShift(const int shiftSize); // colShift void colShift(const int shiftSize); // isA matType bool isA(string matType); // print the contents of this matrix on the screen. void Matrix::print(); // destroy this matrix ~Matrix(); T* operator [](int i) { return array[i];}};
here is my constructor
Template<class T> Matrix<T>::Matrix(int rows, int cols, string matType) : row(rows), col(cols),type(matType) ,array(new T*[rows]) {//the counstructor if (rows < 0 || cols < 0) {//if the matrix cols and rows were minus then will not do anything cout << "enter positive valuses only"; return; } //assert(array != NULL); for (int i = 0; i < row; i++) { array[i] = new T [col]; //assert(array[i] != NULL); } for (int i = 0; i < row; i++) for (int j = 0; j < col; j++) array[i][j] = 0;//initilaizing the matrix to zeros
}
and here is my detructor
template<class T> Matrix <T>::~Matrix() {//destroctur free all the matrix for (int i = 0; i < row; i++) { delete[] this->array[i];//this line it does it one time the next iteration it stucks i couldnt figure whats the problem this->array[i] = NULL; } delete[] this->array; this->array = NULL;
} the problem is at the secound line of the destructor it stucks at the secound iteration like it has nothing to delete there