i'm having problems creating a destructor for a template class that has a private 2d dynamic array. for some reason the destructor destroys the matrix as soon as i am done entering information into the matrix. not sure what went wrong since it compiles fine but gives an error when i enter the info for the first 2 matrices and the program tries to multiply them. the code works if i get rid of the destructor.
template <class T>
class matrix
{
//sudo
friend matrix operator + , *,-,(bunch of friends used to overload)
//end sudo
public:
matrix(): rows(0), cols(0){}
int Arows(){return rows;}
int Acols(){return cols;}
class Proxy
{
matrix& _a;
int _i;
public:
Proxy(matrix& a, int i) : _a(a), _i(i){}
int& operator[](int j) {return _a.Array[_i][j];};
};
Proxy operator[](int i) {return Proxy(*this,i);}
~matrix();
private:
T ** Array;
int rows;
int cols;
};
template<class T>
matrix<T>::~matrix()
{
for (int i=0;i<rows;i++)
delete [] Array[i];
delete [] Array;
}